[Linux] [] docker docker docker-compose and installation

A, docker installation

Centos

Installation docker18.03

  • wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm
  • yum install -y docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm
  • systemctl start docker

Installation docker-compose

  • curl -L https://github.com/docker/compose/releases/download/1.14.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
  • sudo chmod +x /usr/local/bin/docker-compose
  • pip install docker-compose

ubuntu

Since docker official version apt repository may be older, so uninstall the old version may exist:
$ sudo apt-GET-Engine the Remove docker docker docker-ce docker.io
update package apt index:
$ sudo apt-GET Update
to install the following package so that you can use apt repository (repository) via HTTPS:
$ sudo apt-apt GET install -y-HTTPS Transport-CA-Certificates curl the Properties-the Common Software-
added Docker official GPG key:
$ curl -fsSL HTTPS: //download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
use the following command to set the stable repository:
$ sudo the Add-APT-repository "deb [Arch = AMD64] HTTPS: // download. docker.com/linux/ubuntu $ (lsb_release -cs) stable "
and then update the look apt index of the package:
$ sudo apt-GET update
to install the latest version of the CE Docker:
$ sudo apt GET install -y-Docker-ce

Second, the mirror command

1. docker images

  • View mirror already have local

2. docker pull mirror name

  • Download image

3. docker rmi Mirror id / mirror name

  • Remove the mirror (more)

4. docker commit

  • Create a mirror with the operation of the vessel
  • Parameters: -a author -m 'notes' container name (id) image name: Mirror version number

5. docker push mirror name: Mirror version number

  • Upload Mirror

Third, the vessel command

1. docker ps

Check the operation of the vessel

2. docker ps -a

View all containers

3. docker rm container id

Delete container

4. docker stop container id

Stop the container

5. docker start container id

Start container

6. docker restart container id

Restart container

7. docker run

Create and start container

  • -it start interactive terminal (ending need to drive / bin / bash)
  • -d start background
  • -p 80: 8080 port mapping 80 is a host port, a container port 8080
    - name = blog container named

8. control+p+q

Exit container and keep the container runs (termination container exit command exit)

9. docker exec -it container name or container id / bin / bash

Running into the container

10. docker cp

  • Host to the vessel
# 将主机/www/runoob目录拷贝到容器96f7f14e99ab中,目录重命名为www。
docker cp /www/runoob 96f7f14e99ab:/www
  • Container to the host
# 将容器96f7f14e99ab的/www目录拷贝到主机的/tmp目录中。
docker cp  96f7f14e99ab:/www /tmp/

Four, Dockerfile

1. Dockerfile file

# 指定基础镜像文件
FROM ubuntu:latest

# 指定维护者信息
MAINTAINER wanghaifei

# 将代码copy到容器中。如 ADD ./blog /blog 表示将和dockerfile文件同级的blog代码copy到容器的根路径/blog中 ADD 和dockerfile文件相对的项目地址 拷贝到容器中的项目地址 # 指定工作目录 WORKDIR /blog # 复制 COPY 地址 新地址 # 执行更新命令 RUN apt update # 创建项目地址的日志文件或者媒体文件等 RUN mkdir -p /日志logs地址 RUN mkdir -p /媒体media地址 # 指定开放端口 EXPOSE 8000 # 在容器启动时执行命令 ENTRYPOINT ["python"] CMD ["manage.py", "runserver", "0.0.0.0:8000"] 

2. Generate Mirror

docker build -t 镜像名 . (Note that there is a final point to the current directory, the initial building can be slow, need more later.)

Guess you like

Origin www.cnblogs.com/jxd283465/p/11542127.html