CentOs 7 installation Docker-ce community version
Installation docker dependencies
yum install -y yum-utils device-mapper-persistent-data lvm2
Add Docker-ce source software
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Closing edge versions and test versions of Docker-ce
yum-config-manager --enable docker-ce-edge
yum-config-manager --enable docker-ce-test
Yum update source
yum makecache fast
Installation Docker-ce (a first installation)
yum install docker-ce -y
To see if the installation was successful
docker version
Client:
Version: 18.06.1-ce-rc1
API version: 1.38
Go version: go1.10.3
Git commit: 0928140
Built: Wed Aug 8 01:35:58 2018
OS/Arch: linux/amd64
Experimental: false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
View installed version can be supplied (second installation)
yum list docker-ce --showduplicates|sort -r
Install the specified version of Docker-ce
yum install docker-ce-17.09.0.ce -y
Use Docker Docker installation script (third way)
Download Docker installation script
curl -fsSL get.docker.com -o get-docker.sh
Docker execute scripts aliyun mirror
sh get-docker.sh --mirror Aliyun
Replace the warehouse for domestic Docker mirror mirror source
Registration Daocloud account, and log Daocloud
https://www.daocloud.io/mirror#accelerator-doc
Replacing a Daocloud domestic mirroring command
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://e674da1e.m.daocloud.io
Docker restart the domestic source into force
systemctl restart docker
Add Docker random start
systemctl enable docker
Docker mirror Basic Operation
From pulling github mirror
command format:
docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签]
Warehouse Docker mirror address: The address is typically <domain name / IP> [: port number]. The default address is Docker Hub.
Warehouse Name: Two-stage name, namely <username> / <software name>. For Docker Hub, if you do not give the user name, the default for the library, which is the official image.
Example:
docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
c64513b74145: Pull complete
01b8b12bad90: Pull complete
c5d85cf7a05f: Pull complete
b6b268720157: Pull complete
e12192999ff1: Pull complete
Digest: sha256:8c3cced1211d1a566088c0af049cc8cd6f33f5b275e62e6285ca6a13e66a98f0
Status: Downloaded newer image for ubuntu:latest
Lists the local downloaded image
docker image
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 735f80812f90 2 weeks ago 83.5MB
hello-world latest 2cb0d9787c4d 4 weeks ago 1.85kB
Delete local mirror
docker image rm -f 2cb0d9787c4d
According to Mirror ID, image name, summary Remove Mirror
Use Dockerfile build your own image
Create a blank directory and enter the directory
mkdir first
cd first/
Need to upload customized image file to this directory
[root@MiWiFi-R3-srv ~]# cd first/
[root@MiWiFi-R3-srv first]# ll
总用量 12
-rw-r--r--. 1 root root 604 8月 11 15:50 Dockerfile
-rw-r--r--. 1 root root 230 8月 11 14:57 index.js
-rw-r--r--. 1 root root 228 8月 11 14:58 package.json
[root@MiWiFi-R3-srv first]#
Edit Dockerfile file
# 基础镜像来自于 hub.docker.com
FROM centos
#镜像维护信息 https://xiaopangsoftware.taobao.com
MAINTAINER xiaopangruanjianxuetang
#指定工作目录
WORKDIR /app
#将项目相关文件拷贝到app下,如果目录不存在会自动创建
COPY index.js /app
COPY package.json /app
# 安装命令来自于 nodejs 官网 https://nodejs.org/en/download/package-manager/#enterprise-linux-and-fedora
RUN curl --silent --location https://rpm.nodesource.com/setup_10.x | bash - && yum -y install nodejs && npm install
#暴露端口
EXPOSE 8080
#容器启动命令
CMD ["node", "/app/index.js"]
Construction of Mirror
docker build -t xiaopang/centos-nodejs-1 .
-t your name / image name
The latter part of building a successful show results
...
npm notice created a lockfile as package-lock.json. You should commit this file.
added 50 packages in 9.583s
Removing intermediate container 8dc630bdf3fd
---> f0beb800684a
Step 7/8 : EXPOSE 8080
---> Running in f1e679738194
Removing intermediate container f1e679738194
---> 3c0c770cd1c2
Step 8/8 : CMD ["node", "/app/index.js"]
---> Running in 9377ccc41407
Removing intermediate container 9377ccc41407
---> cea31fd11519
Successfully built cea31fd11519
Successfully tagged xiaopang/centos-nodejs-1:latest
View build successful images
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xiaopang/centos-nodejs-1 latest cea31fd11519 7 minutes ago 343MB
centos latest 5182e96772bf 4 days ago 200MB
ubuntu latest 735f80812f90 2 weeks ago 83.5MB
Run the new build images
docker run -p 8080:8080 -d xiaopang/centos-nodejs-1
Access 8080, to verify whether the image produced success
[root@localhost first]# curl http://127.0.0.1:8080
Hello World
Congratulations on your success mirroring
You may encounter problems
docker build 报错[Warning] IPv4 forwarding is disabled. Networking will not work.
- Edit 00-system.conf
vim /usr/lib/sysctl.d/00-system.conf
- Append the following
net.ipv4.ip_forward=1
- Restart card services
systemctl restart network