[Docker] Quickly entering a lightweight shell
docker run -it --rm alpine /bin/ashdocker run -it --rm alpine /bin/ashFirst, get the internal IP of the target container:
docker container inspect $MY_CONTAINERThen you can access the desire port by its IP
x.x.x.x:$TARGET_PORTdocker image lsdocker pull xxx$ docker build -t imagename:2.0 .docker rmi -f $(docker images -q myname)
# or
docker rmi -f image-namedocker rmi -f $(docker images -aq)docker ps -adocker run -it ubuntu bash
# -d: Run in detached mode
# -v: HOST_PATH:CONTAINER_PATH
# --restart=always
# Stop a specific container
docker stop container_name
# Stop all containers
docker kill $(docker ps -q)# Enter an exited container
docker start myname
docker exec -it myname bash
# Detach from a container
Ctrl-p + Ctrl-q inside the container shell
# Re-attach into an up container shell
docker attach mynamedocker rm -f container_namedocker rm -f $(docker ps -aq)# HOST_PORT:CONTAINER_PORT
docker run -p 8000:8000 myimagedocker cp test.txt mycontainer:/app/test.txtdocker volume ls--volumes-from container_name--link container_name (legacy)
# Then you can ping container_name
# It’s better to create a network and add the containers to the network as below
docker network create network-name
# Creates a bridge network by default
docker tag image-name DockerHubAcc/image-namedocker save myimage > myimage.tar
# Using gzip for compression
docker save myimage:tag | gzip > myimage_tag.tar.gzdocker load < myimage.tardocker export mycontainer > mycontainer.tardocker import mycontainer.tar image-namedocker logs container_name
# Use -f to watch the logsdocker statsdocker container prunedocker system prune --volumes  # Only remove dangling images
# -a: Remove all images with no container associatedUse && and \ to chain commands to avoid too many intermediate images get created.
ADD can auto extract .tar.gz and handle remote URL, otherwise use COPY.
Declare auto created volumes using container paths
Only for declaration purpose. docker run -P takes a random port to map to this exposed port.
Most likely the same if used alone. If ENTRYPOINT is used, commands are appended as its arguments (either specified in command line or using CMD. CMD will serve as a default argument in this case)
docker-compose pull# Create all stuffs
docker-compose up -d
# Delete all stuffs
docker-compose down# Start the containers
docker-compose start
# Stop the containers
docker-compose stopdocker-compose logs
docker-compose ps