# Create and run a container docker run [<option(s)>] <image name> <command to run in the container> # Stop a container docker stop <container ID> # Start a container has exited docker start <container ID> # Remove a container docker rm -f <container ID> # Remove container(s) has exited docker container prune # Check current running containers docker ps # Show a container's output docker logs <container ID> # Show processes inside a container docker top <container ID> # Check ports mapping docker ports <container ID> # Get into a background running container docker attach # exit the container cause the container stops docker exec -it <shell name> # start a new terminal of the container, could use ps -aux to see previous processes
option:
-t: terminal a terminal inside the container
-i: allow interaction with container’s STDIN
-d: run container in background mode
-P: map the port of container to a random local machine port
-p: map the port of container to a a customized local machine port
–name: name the container
–rm: clean the container when the container exit
-v: mount a local work directory to container’s directory
Container Advance
1 2 3 4 5 6 7
# Connect container together docker network create -d bridege <network name> # Run a container and add it to the network docker run -itd --network <network name> <image name> /bin/bash # Show network docker network ls
option:
-d: set the type (bridge, overlay) of the docker network