Container management
docker container management
Container creation
- Create a docker container using CentOS image
-it
flag means executing container with attaching their terminal (TTY) and standard input (STDIN)--name
flag makes us set a human readable name of the container- You can easily manage the container if it is named.
- If you don’t specify a name of the container, it uses a commit tag as the name and you can use 3 or 4 leading alphanumeric of the name hash to manage it.
docker run --name centos -it centos
- Detach the attached TTY
- You hit
Ctrl-p Ctrl-q
to exit the attached terminal without shutting down the container. - If you type and run
exit
in your attached terminal, it makes the container turned off. In order to turn on it, usedocker start centos
.- Refer to the next section to connect the restarted container.
- You hit
Connect to your container
Check container’s status
- Use
docker ps
command to list running containers. - For listing all containers event if not running, run
docker ps -a
. - You can retrieve the container named by
centos
bydocker ps -a -f name=centos
.- For more details on
filter
, refer to filter section in the official site. - Instead of the
filter
, you can use grep asdocker ps -a | grep centos
.
- For more details on
- You can get the minimum information by
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
.- You can learn about
format
on docker format section in the official site.
- You can learn about
Connect into the container
exec
sub-command helps us to connect into the container.- You must add
-it
flags to connect it, the following command shows execution ofbash
command to connect to the container.
- You must add
docker exec -it centos bash
- You can use
attach
sub-command to attach your container.- Note that
attach
sub-command makes you directly attach to running environment. It means that if you run exit or invokeSIGTERM
, it terminates your container. Therefore, you useCtrl-p Ctrl-q
shortcut to detach the container.
- Note that
Docker hub
What is docker hub?
- Docker image portal
- In order to search docker images, you can use
search
sub-command.- Also, you can containerize the searched images.
- In order to search docker images, you can use
docker search ubuntu
NAME | DESCRIPTION | STARS | OFFICIAL | AUTOMATED |
---|---|---|---|---|
ubuntu | Ubuntu is a Debian-based Linux operating sys… | 11806 | [OK] | |
dorowu/ubuntu-desktop-lxde-vnc | Docker image to provide HTML5 VNC interface | … | 497 | [OK] |
Using the docker hub
-
- Docker hub is a website for searching docker images.
- In the results, you can find tags of an image in
tags
tab.
- In the results, you can find tags of an image in
- Docker hub is a website for searching docker images.
Using docker image and tags
- Searching docker images on docker hub
- In
tags
tab, find a tag you want to containerize. - In order to containerize an image, describe the image and tag formed by
{image repository}:{tag}
.- The below command show a way to run ubuntu
20.04
.
- The below command show a way to run ubuntu
- In
docker run -it --name ubuntu ubuntu:20.04