Summary of essential Docker commands for developers

Summary of essential Docker commands for developers

This article mainly explains the installation of the Docker environment and the use of common Docker commands. Mastering these is very helpful for the deployment of applications in the Docker environment.

Introduction to Docker

Docker is an open source application container engine that allows developers to package their applications and dependencies into a portable image and then publish it to any popular Linux or Windows machine. Using Docker makes it easier to package, test, and deploy applications.

Docker environment installation

1. Install yum-utils:

yum install -y yum-utils device-mapper-persistent-data lvm2

2. Add the docker repository location to the yum source:

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

3. Install docker:

yum install docker-ce

4. Start Docker:

systemctl start docker

Docker image common commands

Search Mirror

docker search java

640?wx_fmt=png

Download image

docker pull java:8

How to find the versions supported by the image

Since the docker search command can only find out whether the image exists, but cannot find the version supported by the image, we need to search for supported versions through docker hub.

Enter the official website of docker hub, address: https://hub.docker.com

Then search for the required image:

640?wx_fmt=png

Check the versions supported by the image:

640?wx_fmt=png

Download the image:

docker pull nginx:1.17.0

List images

docker images 

640?wx_fmt=png

Deleting an image

Delete an image by specifying its name

docker rmi java:8

Delete an image by specifying its name (mandatory)

docker rmi -f java:8

Force delete all images

docker rmi -f $(docker images)

Docker container common commands

Create and start a container

docker run -p 80:80 --name nginx -d nginx:1.17.0

-d option: indicates background operation

--name option: specifies the name of the container after running as nginx, and then you can operate the container by name

-p option: specifies port mapping, the format is: hostPort:containerPort

List Containers

List running containers:

docker ps

640?wx_fmt=png

List all containers

docker ps -a

640?wx_fmt=png

Stop the container

# $ContainerName and $ContainerId can be queried using the docker ps command	
docker stop $ContainerName(or $ContainerId)

for example:

docker stop nginx	
#or	
docker stop c5f5d5125587

Force stop container

docker kill $ContainerName(or $ContainerId)

Start a stopped container

docker start $ContainerName(or $ContainerId)

Entering the container

First query the pid of the container:

docker inspect --format "{{.State.Pid}}" $ContainerName(or $ContainerId)

Enter the container according to the container's pid:

nsenter --target "$pid" --mount --uts --ipc --net --pid 

640?wx_fmt=png

Deleting a container

Delete the specified container:

docker rm $ContainerName(or $ContainerId)

Force delete all containers;

docker rm -f $(docker ps -a -q)

View the container logs

docker logs $ContainerName(or $ContainerId) 

640?wx_fmt=png

View the IP address of the container

docker logs $ContainerName(or $ContainerId) 

640?wx_fmt=png

Synchronize host time to container

docker cp /etc/localtime $ContainerName(or $ContainerId):/etc/

Check Docker's CPU, memory, network, and IO usage on the host machine

View the status of a specified container:

docker stats $ContainerName(or $ContainerId) 

640?wx_fmt=png

View all containers:

docker stats -a

640?wx_fmt=png

Enter bash inside the Docker container

docker exec -it $ContainerName /bin/bash

640?wx_fmt=png

Modify the storage location of the Docker image

View the storage location of the Docker image:

docker info | grep "Docker Root Dir"

640?wx_fmt=png

Shut down the Docker service:

systemctl stop docker

Move the directory to the target path:

mv /var/lib/docker /mydata/docker

Create a soft link:

ln -s /mydata/docker /var/lib/docker 

640?wx_fmt=png

640?wx_fmt=png

This concludes this article on the essential Docker commands for developers. For more Docker command content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Basic introduction and use of Docker container image related commands
  • Summary and analysis of commonly used Docker commands and examples
  • Detailed explanation of common Docker commands
  • Summary of common docker commands
  • Summary of common docker commands (recommended)
  • A complete guide to the Docker command line (18 things you have to know)
  • Summary of learning Docker commands in one article
  • Introduction to common Docker commands

<<:  MySQL Basic Tutorial: Detailed Explanation of DML Statements

>>:  What you need to know about responsive design

Recommend

Node script realizes automatic sign-in and lottery function

Table of contents 1. Introduction 2. Preparation ...

Summary of uncommon operators and operators in js

Summary of common operators and operators in java...

MySQL data types full analysis

Data Type: The basic rules that define what data ...

Use CSS to draw a file upload pattern

As shown below, if it were you, how would you ach...

Summary of Linux date command knowledge points

Usage: date [options]... [+format] or: date [-u|-...

Detailed explanation of single-row function code of date type in MySQL

Date-type single-row functions in MySQL: CURDATE(...

Detailed tutorial on running multiple Springboot with Docker

Docker runs multiple Springboot First: Port mappi...

Example analysis of the page splitting principle of MySQL clustered index

This article uses an example to illustrate the pa...

Use docker to build kong cluster operation

It is very simple to build a kong cluster under t...

How to use Antd's Form component in React to implement form functions

1. Construction components 1. A form must contain...

How to create a web wireframe using Photoshop

This post introduces a set of free Photoshop wire...

MySQL stored procedure method example of returning multiple values

This article uses an example to describe how to r...

How to open external network access rights for mysql

As shown below: Mainly execute authorization comm...