This series is about Docker container related, I will share some practical tips in my daily work, and I hope some of them will help you too. Maybe some of the strategies you have already used may be useful, so I will share this series as a summary, the first part will introduce how to download and build image, how to start and stop container.
Preface
There are more than ten blogs in this serices. I won’t go into code of docker itself, but
I will share some tips and tricks in my daily work.
When I wrote these blogs, I usedDebian10, docker-ce=5:19.03.2~3-0~debian-buster
# list the images in the host $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE python 3.7.4-stretch b9d77e48a75c 3 weeks ago 940MB
You can use docker build to create a new image.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# make an empty directory $ mkdir tmp && cd tmp
# create Dockerfile $ cat > Dockerfile <<EOF FROM python:3.7.4-stretch RUN echo 1 > /tmp/file.txt EOF
# start build $ docker build . -t my_image
# now, you can get the image just built $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE python 3.7.4-stretch b9d77e48a75c 3 weeks ago 940MB my_image latest 860d8f0fd1c4 25 seconds ago 940MB
Start and stop container
When we have images, we could use docker run to create a container.
1 2 3 4 5 6 7
$ docker run -ti my_image /bin/bash root@9b497582be91:/#
# `docker ps` will display the container currently running $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9b497582be91 my_image "/bin/bash" 44 seconds ago Up 43 seconds magical_beaver
1 2 3 4 5 6 7 8 9 10
# `docker stop` to stop a container
$ docker stop magical_beaver magical_beaver
# `docker ps -a` will display all the containers, even we closed it. $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9b497582be91 my_image "/bin/bash" 2 minutes ago Exited (0) 4 seconds ago magical_beaver