The basic method of using the container and the lower mirror Docker Ubuntu

Docker entry

Docker installation

Installation Steps docker Ubuntu:

Referring URL: HTTPS: //blog.csdn.net/bingzhongdehuoyan/article/details/79411479
1. Since docker version may be more apt official repository of old, so uninstall the old version may exist:

sudo apt-get remove docker docker-engine docker-ce docker.io

2. Update apt Package Index:

sudo apt-get update

3. The following packages are apt to be used so that the repository (Repository) via HTTPS:

sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common

4. Add Docker official GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

5. Use the following command to set the stable repository:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

6 and then update the look apt Package Index:

sudo apt-get update

7. Install the latest version of Docker CE:

sudo apt-get install -y docker-ce

8 on the production system, you may be required to install a specific version of Docker CE, rather than always using the latest version:
a list of available versions:

apt-cache madison docker-ce

Here Insert Picture Description
Selecting a particular version to be installed, the version of the second column is a string, the third column is the store name that indicates which of the packet from the repository, and extended its stability level. To install a specific version, the version string attached to the package name, and (=) are separated by an equal sign:

sudo apt-get install docker-ce=<VERSION>

Verify docker

1. Check the docker service is started:

systemctl status docker
  1. If not started, start the docker services:
sudo systemctl start docker

3. The classic hello world:

sudo docker run hello-world

Here Insert Picture Description
Output is more than proof docker has been successfully installed!

start using

When in use, first need to use a conventional image-based docker to operate the new container, this is based on ubuntu mirror to create a new container . Here ubuntu operating system will create a host container, similar to a virtual machine to use.

Common docker command:

sudo docker images ##查看当前本地可用镜像
sudo docker ps ##查看正在运行的容器id
sudo docker ps -a ##查看创建的所有的容器id,包括正在运行,和停止的

Here, the first load is already ubuntu mirror,

Use the following command to download the image to your local ubuntu:

sudo docker pull ubuntu  

## ubuntu18.04 that is downloaded here is the latest ubuntu mirror, want to use other versions, then you can use sudo docker pull ubuntu16.04 to specify (this time the command is not specifically used in the follow-up can check out)
download the image to the local, can use

sudo docker images#查看本地镜像。

New container based mirroring then the following command:

Sudo docker run -i -t -d -p 8888:8888 ubuntu /bin/bash 

Based ubuntu phrase indicates a new container in the background image, -d shows a discharge vessel background, -p the port mapping between the machine and the container, when the need to map multiple ports require the use of a plurality of instructions -p, e.g. :

Sudo docker run -i -t -d -p 8888:8888 -p 8890:8890 ubuntu /bin/bash
Sudo docker run -i -t -d -p 8888-8890:8888-8890 ubuntu /bin/bash  ##连续端口可用符号“-”连接

After executing the sentence on a new container, the container is placed in the background, so use sudo docker ps can see the running of container id, want to enter the container other installation configuration operation, then execute the following command:

sudo docker ps ##获取想要进去的容器的ID
sudo docker exec -it 容器ID /bin/bash 

Go after the vessel can operate normally, and use the exit command to exit the container, you can use

uname -m && cat /etc/*release

To view details of the current system.
When everything is configured, the current container needs to be uploaded to save the image when executing the following command:

sudo docker commit -m "added ubuntu" -a "cqy" befc2a019cdf images/change3

To hold the mirror, pay attention to the back of the path name in the way of better distinguish the beginning but do not slash /. The first quotes a description of the image, and the second is to create a mirror image of the user, id is the use of ID sudo docker ps -a view of the container you want to save, save the final surface is the name of the new image.
After the save, the input sudo docker imagescan see the image just saved images/change3, but also used as a background to the new run -d container as described above using the method of the subsequent use of the image, then execto enter the vessel operates.

Supplementary expand Docker command

1. running in the background, use the following command to terminate the container:

sudo docker stop 容器ID

The first to use sudo docker ps to see running in the background vessel ID
2. You can delete the specified image using the following command, or all of the image:

docker rmi 镜像名#删除指定的镜像
docker rmi `docker images -a -q`删除本地所有的镜像

3. To generate a docker containers need to transfer the file to the local file transfer using ftp protocol, and then transmits the command to the file by docker containers:

sudo docker ps ##查看容器的容器名,

Assumed to be cranky_wescoff

sudo docker inspect -f '{{.Id}}' cranky_wescoff ##获取容器的完整ID
sudo docker cp helloworld.js 容器完整ID:/home/cqy/test ##将当前目录的js文件复制到容器下的/home/cqy/test目录下。

** Docker mirror and the container at / var / lib / docker / paths, but not authorized to view **

Published 12 original articles · won praise 0 · Views 426

Guess you like

Origin blog.csdn.net/qq_36523203/article/details/103650796