Some basic instructions of docker

Some basic instructions of docker

In recent work, there is relatively little content on MySQL and MongoDB operation and maintenance. My main work involves frequent contact with docker and k8s related content, so I plan to write about this.

In the previous article, I introduced the process of deploying MySQL on Docker. Here is a link for easy review:

Deploy MySQL instance on docker

In the above article, we have talked about what Docker is, the difference between it and a virtual machine, how to install it, and the basic usage. Now let's take a look at other aspects of knowledge.

Some basic instructions

1. Check the container status of the current machine

Normally, we can use the docker ps command to view which containers are running on the current machine, as follows:

[root@VM-16-13-centos ~]# docker ps
 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7a57ee5286e8 kubeguide/tomcat-app:v1 "catalina.sh run" 8 days ago Up 8 days k8s_myweb.7c32387a_myweb-8gmc1_default_b44279ec-48b9-11eb-86e4-5254002dbd85_ec48ef90
b2ad9bea8d0d kubeguide/tomcat-app:v1 "catalina.sh run" 8 days ago Up 8 days k8s_myweb.7c32387a_myweb-60r22_default_b4426b29-48b9-11eb-86e4-5254002dbd85_28dd55c9
4f8f6ea37578 registry.access.redhat.com/rhel7/pod-infrastructure:latest "/usr/bin/pod" 8 days ago Up 8 days k8s_POD.24f70ba9_myweb-8gmc1_default_b44279ec-48b9-11eb-86e4-5254002dbd85_2d2aa42e
3d198ee60f2a registry.access.redhat.com/rhel7/pod-infrastructure:latest "/usr/bin/pod" 8 days ago Up 8 days k8s_POD.24f70ba9_myweb-60r22_default_b4426b29-48b9-11eb-86e4-5254002dbd85_416acda7
94332658780b busybox "sh -c 'tail -f /l..." 6 weeks ago Up 6 weeks k8s_busybox.5057389f_volume-pod_default_13702698-2b17-11eb-86e4-5254002dbd85_a553d58b
f11f11999c42 tomcat "catalina.sh run" 6 weeks ago Up 6 weeks k8s_tomcat.aeb855f2_volume-pod_default_13702698-2b17-11eb-86e4-5254002dbd85_aa729e3d
d2ec1526079f kubeguide/redis-master "redis-server /etc..." 6 weeks ago Up 6 weeks k8s_redis.deb7361f_redis-php_default_f70a055b-2b18-11eb-86e4-5254002dbd85_23135019
5b83d7645b1f registry.access.redhat.com/rhel7/pod-infrastructure:latest "/usr/bin/pod" 6 weeks ago Up 6 weeks k8s_POD.3fe22e5d_redis-php_default_f70a055b-2b18-11eb-86e4-5254002dbd85_c418f108
3b7634ee3eff registry.access.redhat.com/rhel7/pod-infrastructure:latest "/usr/bin/pod" 6 weeks ago Up 6 weeks k8s_POD.24f70ba9_volume-pod_default_13702698-2b17-11eb-86e4-5254002dbd85_0610ed58
4784586d01e0 mysql "docker-entrypoint..." 6 weeks ago Up 6 weeks k8s_mysql.16d54d16_mysql-pd7jr_default_0032bce0-2b0f-11eb-98ad-5254002dbd85_d775f414
c8acc287dc06 registry.access.redhat.com/rhel7/pod-infrastructure:latest "/usr/bin/pod" 6 weeks ago Up 6 weeks k8s_POD.1d520ba5_mysql-pd7jr_default_0032bce0-2b0f-11eb-98ad-5254002dbd85_94c9c30a

Other notes:

The -a parameter is used to view all containers, including those that are running and stopped. If -a is not added, only the running containers are displayed.

-l parameter, which lists the last running container, including running and stopped containers.

-q parameter, quite, only displays the container ID

-s parameter, size, displays the total file size

2. Download or pull an image.

You can use docker pull or docker run as follows:

[root@VM-16-13-centos ~]# docker run -i -t ubuntu /bin/bash
Unable to find image 'ubuntu:latest' locally
Trying to pull repository docker.io/library/ubuntu ...
 latest: Pulling from docker.io/library/ubuntu
da7391352a9b: Downloading [=> ] 588.8 kB/28.56 MB
14428a6d4bcd: Download complete
 2c2d948710f2: Download complete

 [root@VM-16-13-centos ~]# docker pull mysql
Using default tag: latest
Trying to pull repository docker.io/library/mysql ...

When you use the docker run command to pull an image, Docker will automatically give it a random name. If you do not want to use a randomly named container, you can use the --name parameter to specify the name. If you do not specify the version number of the image, the latest version of the image will be automatically pulled.

The docker run command is often used with the -d parameter: it means running a guarded container in the background

You can also use the --restart=always parameter to restart the container. Of course, the default is not to restart the container.

3. Start, stop and restart containers

Note that the last part is the container ID or container name.

docker start containerID/name

docker stop containerID/name

docker restart containerID/name

4. View the process in the container

The docker top command can view all processes in a container.

[root@VM-16-13-centos ~]# docker top k8s_mysql.16d54d16_mysql-pd7jr_default_0032bce0-2b0f-11eb-98ad-5254002dbd85_d775f414
        UID PID PPID C STIME TTY TIME CMD
root 5059 5044 0 2020 pts/5 00:00:00 /bin/bash
root 5152 5059 0 2020 pts/5 00:00:00 mysql -uroot -px xxxx
root 13644 24879 0 2020 pts/4 00:00:00 mysql -uroot -px xxxx
polkitd 18853 18837 0 2020 ? 01:31:43 mysqld
root 24153 24137 0 2020 pts/1 00:00:00 /bin/bash
root 24376 24153 0 2020 pts/1 00:00:00 mysql -uroot -px xxxx
root 24879 24864 0 2020 pts/4 00:00:00 /bin/bash
root 25833 25817 0 23:45 pts/8 00:00:00 /bin/bash
root 28493 28477 0 2020 pts/3 00:00:00 /bin/bash
root 28609 28493 0 2020 pts/3 00:00:00 mysql -uroot -px xxxx
root 29484 29468 0 2020 pts/2 00:00:00 /bin/bash
root 29601 29484 0 2020 pts/2 00:00:00 mysql -uroot -px xxxx

5. Execute commands inside the container

For example, we create a folder inside the container, where the container ID is 4784586d01e0, and create a data folder

[root@VM-16-13-centos ~]# docker exec -d 4784586d01e0 mkdir -p /data
[root@VM-16-13-centos ~]# docker exec -it 4784586d01e0 /bin/bash
root@mysql-pd7jr:/# ls -l
total 76
drwxr-xr-x 2 root root 4096 Nov 17 00:00 bin
drwxr-xr-x 2 root root 4096 Sep 19 21:39 boot
drwxr-xr-x 2 root root 4096 Jan 5 15:51 data
drwxr-xr-x 5 root root 360 Nov 20 09:16 dev
drwxr-xr-x 2 root root 4096 Nov 18 08:16 docker-entrypoint-initdb.d
.....

6. Delete the container

docker rm containID/name

Note that before deleting a container, you need to stop the container first, otherwise the deletion will result in an error.

docker rm `docker -a -q`

This command can delete all containers.

The above are the details of some basic docker instructions. For more information about basic docker instructions, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of Dockerfile to create a custom Docker image and comparison of CMD and ENTRYPOINT instructions
  • Docker container operation instructions summary and detailed explanation
  • Detailed explanation of the specific use of the ENV instruction in Dockerfile
  • Explanation of Dockerfile instructions and basic structure
  • Detailed explanation of Dockerfile instructions in Docker to create images
  • Introduction to Dockerfile instructions ADD and COPY
  • A brief introduction to the Dockerfile instruction VOLUME
  • Docker instructions collection and arrangement (collection)
  • Dockerfile instructions explained

<<:  How to set the page you are viewing to not allow Baidu to save its snapshot

>>:  JavaScript Function Currying

Recommend

Three ways to check whether a port is open in a remote Linux system

This is a very important topic, not only for Linu...

Front-end JavaScript thoroughly understands function currying

Table of contents 1. What is currying 2. Uses of ...

JavaScript Array Detailed Summary

Table of contents 1. Array Induction 1. Split a s...

JavaScript article will show you how to play with web forms

1. Introduction Earlier we introduced the rapid d...

Analysis of the Neglected DOCTYPE Description

doctype is one of them: <!DOCTYPE HTML PUBLIC &...

Let's talk about the storage engine in MySQL

Basics In a relational database, each data table ...

Docker+gitlab+jenkins builds automated deployment from scratch

Table of contents Preface: 1. Install Docker 2. I...

CSS to achieve Cyberpunk 2077 style visual effects in a few steps

background Before starting the article, let’s bri...

Analysis of MySQL latency issues and data flushing strategy process

Table of contents 1. MySQL replication process 2....

How to develop Java 8 Spring Boot applications in Docker

In this article, I will show you how to develop a...

Detailed explanation of non-parent-child component communication in Vue3

Table of contents First method App.vue Home.vue H...

Share 8 very useful CSS development tools

CSS3 Patterns Gallery This CSS3 pattern library s...