文章目录
常用命令
打印image列表
docker images
打印container列表
docker container ls
docker container ls --all
拉取官方镜像
docker pull ubuntu:16.04
拉取自己的镜像
docker login
(登录账号)
docker image pull timleezhong/helloworld
删除镜像
docker image rm <REPOSITORY:TAG>或者IMAGE ID>
docker rmi <REPOSITORY:TAG>或者IMAGE ID>
保存镜像为tar包
docker image save -o ubuntu.tar.gz ubuntu:16.04
docker save -o ubuntu.tar.gz ubuntu:16.04
从tar包导入镜像
docker load -i <tar file>
docker load -i ubuntu.tar.gz
推送自己的镜像到仓库
docker login
docker image push timleezhong/helloworld
创建容器
docker run -d -it -p 8022:22 --name ubuntu ubuntu:16.04
docker container run --publish 8000:8080 --detach --name ubuntu ubuntu:16.04
启动容器
docker start ubuntu
在正在运行的容器中运行一条命令
docker exec -it ubuntu bash
docker exec -it ubuntu python
docker exec -it ubuntu ls
删除容器
docker container rm --force ubuntu
提交容器到镜像
docker commit CONTAINER REPOSITORY:TAG
从Dockerfile构建镜像
- docker build -t caffe:gpu standalone/gpu 【从standalone/gpu目录下的Dockerfile构建镜像caffe:gpu】
- docker image build -t bulletinboard:1.0 .
临时使用container
- docker run -it ubuntu bash 【try something more ambitious热切】
入门教程
https://docs.docker.com/get-started/part2/
用Dockerfile定义一个容器
# Use the official image as a parent image
FROM node:current-slim
# Set the working directory
WORKDIR /usr/src/app
# Copy the file from your host to your current location
COPY package.json .
# Run the command inside your image filesystem
RUN npm install
# Inform Docker that the container is listening on the specified port at runtime.
EXPOSE 8080
# Run the specified command within the container.
CMD [ "npm", "start" ]
# Copy the rest of your app's source code from your host to your image filesystem.
COPY . .
建立并测试您的镜像
进入Dockerfile所在目录,然后执行:
docker image build -t bulletinboard:1.0 .
bulletinboard:1.0表示REPOSITORY:TAG
将镜像作为容器运行
docker container run --publish 8000:8080 --detach --name bb bulletinboard:1.0
删除:
docker container rm --force bb
该–force选项将删除正在运行的容器。
发布镜像
准备工作:创建docker账号
docker login
docker image push timleezhong/helloworld
docker image pull timleezhong/helloworld
拉取官方镜像
docker pull ubuntu:16.04
安装
https://docs.docker.com/install/linux/docker-ce/ubuntu/
https://github.com/NVIDIA/nvidia-docker
阉割版安装
apt install docker.io
systemctl start docker
docker pull ubuntu
docker save -o ubuntu.tar.gz ubuntu:latest
配置
允许非root用户使用
sudo usermod -aG docker your-user
测试
sudo docker run hello-world
Usage
#### Test nvidia-smi with the latest official CUDA image
$ docker run --gpus all nvidia/cuda:9.0-base nvidia-smi
# Start a GPU enabled container on two GPUs
$ docker run --gpus 2 nvidia/cuda:9.0-base nvidia-smi
# Starting a GPU enabled container on specific GPUs
$ docker run --gpus '"device=1,2"' nvidia/cuda:9.0-base nvidia-smi
$ docker run --gpus '"device=UUID-ABCDEF,1"' nvidia/cuda:9.0-base nvidia-smi
# Specifying a capability (graphics, compute, ...) for my container
# Note this is rarely if ever used this way
$ docker run --gpus all,capabilities=utility nvidia/cuda:9.0-base nvidia-smi
离线安装
docker pull nvidia/7.5-cudnn5-runtime-ubuntu14.04
docker save -o 7.5-cudnn5-runtime-ubuntu14.04.tar.gz nvidia/cuda:7.5-cudnn5-runtime-ubuntu14.04
docker load < 7.5-cudnn5-runtime-ubuntu14.04.tar.gz
docker run -d --shm-size 60G --name cudnn75 --restart=always -v ~/torch0.2_env:/workdir --gpus all -p 1022:22 nvidia/cuda:7.5-cudnn4-devel-ubuntu14.04
docker run -d --shm-size 60G --name cudnn75 --restart=always -v ~/torch0.2_env:/workdir --gpus all -p 1022:22 nvidia/cuda:7.5-cudnn4-devel-ubuntu14.04
docker exec -it cuda-75 /bin/bash