$ docker image pull alpine
$ docker image ls
$ docker container create -i -t alpine sh
$ docker container start CONTAINER_ID
$ docker container run -i -t --name myalpine alpine sh
By pressing Ctrl-p Ctrl-q from a running container.
$ docker container ls
$ docker container attach CONTAINER_NAME
$ docker container run -d ubuntu /bin/bash -c
List the currently running containers again
Did you notice that your detached container is not showing up in the list? Can you find out why?
Let’s try and find out. List all containers, be they running, stopped or detached
$ docker container ls --all
Did you identify the container that you ran in detached mode? Why did it exit gracefully?
How to see logs of a container ?
$ docker container logs CONTAINER_ID
$ docker container stop CONTAINER_ID
$ docker container pause be9f86d4d1df
$ docker container stop CONTAINER_NAME
$ docker container rm CONTAINER_NAME
$ docker container rm -f CONTAINER_NAME
$ docker container run --rm --name temp_container alpine ping -c 3 amazon.com
$ docker container run -h alpine -it --rm alpine sh
$ docker container run -it --env "WEB_HOST=172.168.1.1" --rm alpine sh
$ docker container inspect CONTAINER_ID
$ docker container run -d --name memorylimitAlpine --memory "200m" alpine top
$ docker container inspect memorylimitAlpine | grep -i Mem
$ docker container exec CONTAINER_ID ip a
N.B: With docker container exec
option, we can create any process inside an already running container.
This option is very useful for debugging.
$ docker container run -d --restart=always --name mywebserver nginx
$ echo "This is our container bootcamp" > index.html
$ docker container cp index.html mywebserver:/usr/share/nginx/html/
$ docker container inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mywebserver
$ docker container run -d --label env=prod nginx
$ docker container run -d --label env=dev nginx
$ docker container ls --filter label=env=dev
$ docker container rm -f `docker container ls -q -a`
$ docker container prune