你 一会儿看我 一会儿看云 我觉得 你看我时很远 你看云时很近
《远和近》,顾城
# Docker (一)
# 安装
# 测试环境
- OS: Deepin 15.6 桌面版 x64
- CPU: Intel Core i5-3210M
- RAM: 8GB
# 安装步骤
- 确定发行版以及版本号
- 安装依赖工具
- 安装密钥
- 添加docker源
- 安装docker 具体过程可参考“Deepin文档-Docker安装”或“Docker官方文档-安装篇”。 需要注意的是:
- 密钥和docker的下载地址为了保证下载速度,尽量设置为国内的源,例如阿里云的源:https://mirrors.aliyun.com/docker-ce/
# 配置
- 为了提高docker镜像的下载速度,修改/etc/docker/daemon.json中的registry-mirrors,将镜像的下载路径配置为阿里云的docker加速器地址
- docker的配置文件改动以后,记得通过systemctl重新加载配置文件并重启docker进程
- 将当前用户加入docker用户组:usermod -aG docker username,避免运行docker命令的时候使用sudo
# 常用命令
# 镜像管理
# 镜像查看
# ls 只显示顶层镜像
docker image ls
# ls -a 显示所有的镜像,包括中间层镜像
docker image ls -a
# 镜像下载
docker image pull image_name
# 镜像删除
# Remove specified image from this machine
docker image rm <image id>
# Remove all images from this machine
docker image rm $(docker image ls -a -q)
# 镜像构建
# Create image using this directory's Dockerfile
docker build -t friendlyhello .
# Dockerfile
# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "app.py"]
# another Dockerfile
FROM mariadb:latest
EXPOSE 3306
ENV MYSQL_RANDOM_ROOT_PASSWORD yes
ADD mariadb_user.sql /docker-entrypoint-initdb.d
# 镜像运行
# Run "friendlyname" mapping port 4000 to 80
docker run -p 4000:80 friendlyhello
# Same thing, but in detached mode
docker run -d -p 4000:80 friendlyhello
# run ubuntu and open interactive shell
docker run -it ubuntu /bin/sh
# 容器管理
# 容器查看
# List all running containers
docker container ls
docker ps
# List all containers, even those not running
docker container ls -a
docker ps -a
# 容器运行
docker container start <container_id>
# 进入运行的容器
docker attach <container_id>
# 容器停止
# Gracefully stop the specified container
docker container stop <hash>
# Force shutdown of the specified container
docker container kill <hash>
# 容器删除
# Remove specified container from this machine
docker container rm <hash>
# Remove all containers
docker container rm $(docker container ls -a -q)