docker 安装使用文档

docker安装

安装前提

CentOS 7以上版本

https://docs.docker.com/engine/installation/linux/docker-ce/centos/#install-from-a-package

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-centos-7

 

安装步骤

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

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

sudo yum makecache fast

sudo yum install docker-ce

注意:安装带版本号的稳定版的docker-ce,不要安装不稳定的最新版本。

启动docker服务:

service docker start

systemctl

添加docker的用户组,避免每次执行docker需要sudo

sudo usermod -aG docker $(whoami)

 

 

docker常用命令

查看镜像

docker images

 

查看容器

docker ps –a

 

启动

docker run –d –p 5000:5000 –v /usr/apps/software/docker/registry:/tmp/registry registry

-d 后台启动

-p 端口映射

-v  Bind mount a volume (e.g., from the host: -v /host:/container, from Docker: -v /container)

--rm Automatically remove the container when it exits (incompatible with -d),default false

 

删除镜像

docker rmi [image-id]

 

删除容器

docker rm [container-id]

 

停止容器

docker stop [container-id]

 

进入容器

docker attach [image-name]

 

docker exec –ti [container-id] /bin/bash

 

查看容器日志

docker logs [container_id]

 

提交容器d

docker commit [container_id] [image-name]

 

存出镜像

docker save –o centos7_pg93_1.1.tar centos7_pg93:1.1

 

docker run --name yourappname -e POSTGRES_PASSWORD=mysecretpassword  -e POSTGRES_USER=xxx -d -p xxxx:5432 postgres

 

查看docker容器的IP地址

docker inspect --format='{{.NetworkSettings.IPAddress}}' $CONTAINER_ID

 

docker build --no-cache=true -t friendlyname .  # Create image using this directory's Dockerfile

docker run -p 4000:80 friendlyname  # Run "friendlyname" mapping port 4000 to 80

docker run -d -p 4000:80 friendlyname         # Same thing, but in detached mode

docker container ls                                # List all running containers

docker container ls -a             # List all containers, even those not running

docker container stop <hash>           # Gracefully stop the specified container

docker container kill <hash>         # Force shutdown of the specified container

docker container rm <hash>        # Remove specified container from this machine

docker container rm $(docker container ls -a -q)         # Remove all containers

docker image ls -a                             # List all images on this machine

docker image rm            # Remove specified image from this machine

docker image rm $(docker image ls -a -q)   # Remove all images from this machine

docker login             # Log in this CLI session using your Docker credentials

docker tag username/repository:tag  # Tag for upload to registry

docker push username/repository:tag            # Upload tagged image to registry

docker run username/repository:tag                   # Run image from a registry

 

镜像市场

官方市场

Docker store

 

Daocloud

http://hub.daocloud.io/

 

docker centos7基础镜像

下载镜像

从docker hub下载centos

docker pull centos

注意:安装带版本号的稳定版的centos,不要安装不稳定的centos最新版本。

 

Docker hub

https://hub.docker.com/explore/

 

docker store

https://store.docker.com/

 

设置时区

先查看时区

date -R

修改时区:

(将Asia/shanghai-上海时区写入当前时区)#cp -f /usr/share/zoneinfo/Asia/Shanghai     /etc/localtime

提示是否覆盖,输入Y回车,

然后#date 

查看时区和时间(CST,中国时区)

http://jingyan.baidu.com/article/647f01159ae1e67f2148a80a.html

添加中文编码方式

 

中文环境设置:

localedef -i zh_CN -f GB2312 zh_CN

localedef -i zh_CN -f GB2312 zh_CN.GB2312

localedef -i zh_CN -f GBK zh_CN.GBK

localedef -i zh_CN -f UTF-8 zh_CN.UTF-8

 

 

locale -a

localectl list-locales | grep zh

https://www.zybuluo.com/yangDL/note/427453

 

 

systemctl docker Failed to get D-Bus connection 报错

http://www.bubuko.com/infodetail-1314362.html

 

docker的centos7镜像systemctl问题

解决docker 官方镜像centos7的systemctl不起作用的方法

docker run --privileged  -p 15432:5432 -p 10022:22 -d centos7_pg93:0.1 /usr/sbin/init

添加运维管理所需包

sar

htop

net-tools:ping、ifconfig、telnet、netstat

 

 

 

 

你可能感兴趣的:(技术,docker,分布式部署)