Published 5月 29, 2019 by with 0 comment

3 - 01 - Container State




In this lab, I will study how to manage container.

1. Running container in Back-end (-d).
$ docker run -d ubuntu /bin/bash -c "while true ; do sleep 1; echo Back-end; done"


2. Running container in Fornt-end. Container name is Front_end.
$ docker run --name Front_end ubuntu /bin/bash -c "while true ; do sleep 1; echo Front-end; done"


3. Open another terminal, check two containers state
$ docker ps


4. There are two ways to into the container. attach and exec.
4-1 For attach, using --sig-proxy=false, so CTRL-c will exit without stopping the container itself.
$ docker attach --sig-proxy=false eae2717f0d74


4-2 For exec, it will create a new terminal in the container. Using exit to exit container without stopping the container itself.
$ docker exec -it dd1597d4d404 /bin/bash


5. Stop/start/restart container.
$ docker stop #can stop the container. (SIGTERM)
$ docker kill #can stop the container. (SIGKILL)
$ docker start #can run container.
$ docker restart #which is running docker stop and then docker start. The cantainer ID will be same.
$ docker run --restart=always #It will always run the container.
$ docker run --restart=on-failure:3 #It will restart the container 3 times.



6. If we need to pause container for do snapshot. We can use $ docker pause / unpause.
$ docker pause
$ docker unpause


7. When docker runs for a long time, it will a lot of exited container. These container will consume the host resource.
$ docker ps -a #Show all containers
$ docker rm #Remove one or more containers
$ docker rm -v $(docker ps -aq -f status=exited) #Remove all of exited container



最初發表 / 最後更新: 2019.05.29 / 2019.05.29

0 comments:

張貼留言