Container management
docker container management
Container creation
- Create a docker container using CentOS image
-itflag means executing container with attaching their terminal (TTY) and standard input (STDIN)--nameflag 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-qto exit the attached terminal without shutting down the container. - If you type and run
exitin 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 pscommand to list running containers. - For listing all containers event if not running, run
docker ps -a. - You can retrieve the container named by
centosbydocker 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
formaton docker format section in the official site.
- You can learn about
Connect into the container
execsub-command helps us to connect into the container.- You must add
-itflags to connect it, the following command shows execution ofbashcommand to connect to the container.
- You must add
docker exec -it centos bash
- You can use
attachsub-command to attach your container.- Note that
attachsub-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-qshortcut to detach the container.
- Note that
Docker hub
What is docker hub?
- Docker image portal
- In order to search docker images, you can use
searchsub-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
tagstab.
- 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
tagstab, 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