Getting started with the simple use of Docker

Preface: 

Docker is an open source application container engine that lets developers can package their applications and dependencies into a portable mirror, and then publish to any of the popular Linux or Windows machine. In recent years, domestic development of Docker in full swing, especially in the Internet company, Docker use is very common, greatly improving the efficiency of application maintenance and reduce the cost of cloud computing application development. This article mainly take you on Docker, introduced Docker installation and simple to use.

1. Install Docker

Docker want to learn, we must first install Docker, from 17.03 after the release into CE (Community Edition: Community Edition) and EE (Enterprise Edition: Enterprise Edition), below our CentOS system as an example, Docker community version of the installation:

Uninstall the old version of the 
old version of Docker called docker or docker-engine, use the following command to uninstall the old version:

$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

 Installation dependencies 

#配置yum源
sudo yum-config-manager \
--add-repo \
https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo

#安装依赖包
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2

Install the latest version of Docker CE

sudo yum-config-manager --enable docker-ce-edge
sudo yum makecache fast
sudo yum install docker-ce

Start Docker CE 

sudo systemctl enable docker
sudo systemctl start docker

Establish docker User Group 

sudo groupadd docker
sudo usermod -aG docker $USER

Hello-world test run 

$ docker run hello-world
 Unable to find image 'hello-world:latest' locally
 latest: Pulling from library/hello-world
 ca4f61b1923c: Pull complete
 Digest: sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
 Status: Downloaded newer image for hello-world:latest
 Hello from Docker!
 This message shows that your installation appears to be working correctly.

 To generate this message, Docker took the following steps:
  1. The Docker client contacted the Docker daemon.
  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
      (amd64)
  3. The Docker daemon created a new container from that image which runs the
      executable that produces the output you are currently reading.
  4. The Docker daemon streamed that output to the Docker client, which sent it
      to your terminal.

  To try something more ambitious, you can run an Ubuntu container with:
   $ docker run -it ubuntu bash

  Share images, automate workflows, and more with a free Docker ID:
   https://hub.docker.com/

  For more examples and ideas, visit:
   https://docs.docker.com/get-started/

We did this Docker installation, the same, Docker installed in the Windows system and macOS system is also very easy to download Docker Desktop installation package to install and use, official documents specifically refer to the following:

https://docs.docker.com/docker-for-windows/install/
https://docs.docker.com/docker-for-mac/install/

2. Common Commands

Docker learning, we must first know its overall architecture, here briefly in three basic concepts under Docker:

  • Image (Image) : Docker image (Image), the equivalent of a root file system. For example, the official mirroring ubuntu: 16.04 contains the complete set of Ubuntu16.04 minimum system root file system.
  • The container (Container) : mirror image (Image) and the container (Container), like object-oriented programming classes and instances, the mirror is statically defined, the container is a solid mirror runtime. Container can be created, start, stop, delete, pause.
  • Warehouse (the Repository) : warehouse code can look at the control center, to save the image.

Mirror-related commands: 

1) Find a mirror
docker search image name (for example redis)

2) Download mirror
docker pull mirror name

3) Check local mirror list
docker images

4) remove the mirror

Mirror ID docker rmi

Container-related commands: 

1) run-time image into a container

Docker run --name name of the vessel's name -d mirror

-d represents the detached, the console will not be hindered means that after completion of sentence execution command, enter the command can continue operating.

2) get a list of running container

docker ps

3) to obtain a list of all vessels containing the views of exit

docker ps -a

4) Stop and start the container

docker start / stop container name / id

5) port mapping

You need to map the software running in the container port to port your host or hosts on the LAN is not accessible.

docker run -d -p 6378:6379 --name myRedis redis

-p: container port mapping 6379 to a host port 6378

6) Delete container

docker rm id

7) Check the current container logs

docker logs name/id

8) Login container

docker exec -it container name bash

-i: to ensure that our input is active

-t: assigns a pseudo-terminal

Log in to access the current container after landing routine Linux commands can operate in the container, you can also use the exit command Log.

to sum up: 

This article introduces the Docker installation and commonly used commands, as the introductory article, I hope for your help. In fact, as the basis for Docker tool, it is recommended that you learn about, for example, you can start a second level MySQL instance, a new version can also be used to test Docker run. Next article intends to write down how to run and configure MySQL in Docker, the next look forward to it!

References: 

Sui Suinian:
Recently the upcoming double 11, the major server vendors have special offers, entry-level servers to buy 88 yuan a year, Tencent Ali clouds and clouds have this activity, we recommend a look. Buy cloud server, you can learn Linux, MySQL, Docker, Git, etc., can also deploy personal websites, you need to buy a small partner can test play Oh! Copy the following link into your browser open to enter the official website to buy surface.

Ali Cloud:
https://www.aliyun.com/1111/2019/group-buying-share?ptCode=F6718C2981638C225DDA9F79172CF1F4647C88CF896EF535&share_source=copy_link

Tencent says:
https://cloud.tencent.com/act/double11/reserve?spread_hash_key=1isLgW

Guess you like

Origin blog.51cto.com/10814168/2447071