docker在centOS7下安装与使用

自闭症网瘾萝莉.ら 提交于 2020-08-09 21:29:51

docker启动停止

sudo systemctl start docker.service 
sudo systemctl stop docker.service
sudo systemctl restart docker.service 
sudo systemctl status docker.service 
sudo systemctl enable docker

sudo docker ps -a ## <-- 列出已有的images ##
sudo docker stop 17dd4ab4cda2 ##<-- 17dd4ab4cda2为container id ##
sudo docker rm 17dd4ab4cda2 ##<-- 删除container id ##
sudo docker rmi image_name ##<-- 删除images ##
sudo docker ps -a | grep Exit | awk '{print $1}' | xargs docker rm ##<-- 删除exit的images ##
docker info  ## <-- 确认Docker是否正确安装 ##
# docker rm --force `docker ps -qa`

遇到问题

cenOS启动docker后,虚拟机ping不通?

原因是docker守护进程 默认使用172.17.0.1作为网段,可以通过ifconfig发现docker0的网络,与宿主机的网段冲突;

解决方法:https://forums.docker.com/t/change-default-docker0-bridge-ip-address/30470/8 ,即在/etc/docker下增加daemon.json文件,修改docker启动默认网段

执行 _ifconfig docker0 down _即可

ifconfig命令

` docker info`

Reuslts in Get http:///var/run/docker.sock/v1.12/info: dial unix /var/run/docker.sock: permission denied

解决方法

增加docker用户组

sudo groupadd docker

赋予用户组所有用户docker权限

sudo usermod -a -G docker $USER

退出ssh客户端,重新登录

cenOS下docker安装

yum install docker

yum install epel-release

yum install docker-io

systemctl enable docker

systemctl start docker  
systemctl status docker

docker run hello-world

Node方式发布Vue应用配置

Dockerfile

FROM node:9.11.1-alpine

# install simple http server for serving static content
RUN npm install -g http-server

# make the 'app' folder the current working directory
WORKDIR /app

# copy both 'package.json' and 'package-lock.json' (if available)
COPY package*.json ./

# install project dependencies
RUN npm install

# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY . .

# build app for production with minification
RUN npm run build

EXPOSE 8888
CMD [ "http-server", "dist" ,"-p 8888"]

start.sh

#!/bin/sh

## start docker
cd frontend/tms
echo "删除之前的容器..."
docker rm --force `docker ps -qa`
echo "生成镜像..."
docker build -t  tms_frontend:1.0 .
echo "启动容器..."
docker run -p 8888:8888 --net=host --rm --name tms_frontend  tms_frontend:1.0  &

docker-compose安装

sudo curl -L https://github.com/docker/compose/releases/download/1.20.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

sudo chmod a+x /usr/local/bin/docker-compose
docker-compose --version

搭建docker私服

开启私服端口5000

使用官方的 registry 镜像来启动本地的私有仓库,启动

firewall-cmd --zone=public --add-port=5000/tcp --permanent
docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry docker.io/registry
docker start $(docker ps -l | grep registry | awk '{print $1}') #启动仓库

端口如果没有开启,在pull镜像和curl查看registry中镜像时,出现connection refused错误

配置私服ip地址

docker registry使用的是https,所以当用docker pull命令下载远程镜像时,如果远程docker registry是非https的时候就会报错.

为了解决这个问题需要在启动docker server时增加启动参数

打开/etc/docker/daemon.json,增加insecure-registries

修改完配置后,执行以下命令

systemctl daemon-reload
sudo systemctl restart docker.service

准备镜像

docker pull hello-world
docker tag bf756fb1ae65 172.18.0.57:5000/hello:latest
docker push 172.18.0.57:5000/hello
curl -X GET http://172.18.0.57:5000/v2/_catalog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!