Installation et configuration 2.2 Docker

CentOS 7 Installation Docker-ce version communautaire

Installation dépendances docker

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

Ajouter logiciel source Docker-ce

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

La fermeture des versions de pointe et des versions de test de Docker-ce

yum-config-manager --enable docker-ce-edge
yum-config-manager --enable docker-ce-test

source de mise à jour yum

yum makecache fast

Installation Docker-ce (une première installation)

yum install docker-ce -y

Pour voir si l'installation a réussi

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?

Voir la version installée peut être fourni (deuxième installation)

yum list docker-ce --showduplicates|sort -r  

Installer la version spécifiée de Docker-ce

yum install docker-ce-17.09.0.ce -y

Utiliser un script d'installation Docker Docker (troisième voie)

Télécharger Docker script d'installation

curl -fsSL get.docker.com -o get-docker.sh

Docker exécuter des scripts aliyun miroir

sh get-docker.sh --mirror Aliyun

Remplacer l'entrepôt pour la source miroir miroir Docker intérieur

Inscription Daocloud compte, et connectez-vous Daocloud

https://www.daocloud.io/mirror#accelerator-doc

Le remplacement d'une commande de mise en miroir domestique Daocloud

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://e674da1e.m.daocloud.io

Docker redémarrer la source nationale en vigueur

systemctl restart docker 

Ajouter Docker début aléatoire

systemctl enable docker 

Docker miroir Fonctionnement de base

De tirer miroir github
format de commande:

docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签]

Adresse miroir Entrepôt Docker: L'adresse est généralement <nom de domaine / IP> [: numéro de port]. L'adresse par défaut est Docker Hub.
Nom Entrepôt: nom en deux étapes, à savoir <nom d' utilisateur> / <nom du logiciel>. Pour Docker Hub, si vous ne donnez pas le nom d'utilisateur, la valeur par défaut de la bibliothèque, qui est l'image officielle.

exemple:

 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

Listes de l'image téléchargée locale

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

Supprimer miroir local

docker image rm -f 2cb0d9787c4d

Selon Mirror ID, nom de l'image, résumé Supprimer le miroir

Utilisez Dockerfile construire votre propre image

Créez un répertoire vide et entrez le répertoire

mkdir first 
cd first/

Vous avez besoin de télécharger le fichier d'image personnalisé dans ce répertoire

[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]# 

Modifier le fichier Dockerfile

# 基础镜像来自于 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 du Miroir

docker build -t xiaopang/centos-nodejs-1 .

-t votre nom / nom de l'image

La dernière partie de la construction d'un spectacle réussi de résultats

...
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

Voir construire des images réussies

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

Exécutez les nouvelles images de construction

docker run -p 8080:8080 -d xiaopang/centos-nodejs-1

Accès 8080, pour vérifier si l'image a produit le succès

[root@localhost first]# curl http://127.0.0.1:8080
Hello World

Félicitations pour le succès de la mise en miroir

Vous pouvez rencontrer des problèmes

construction docker 报错 [Avertissement] le transfert IPv4 est désactivé. Mise en réseau ne fonctionnera pas.

  1. Modifier 00-system.conf
vim /usr/lib/sysctl.d/00-system.conf
  1. Append ce qui suit
net.ipv4.ip_forward=1
  1. services de cartes redémarrage
systemctl restart network

Je suppose que tu aimes

Origine www.cnblogs.com/l-hh/p/12567320.html
conseillé
Classement