Docker在Ubuntu上安装与使用

https://docs.docker.com/docker-hub/quickstart/
https://docs.docker.com/engine/reference/commandline/run/
https://docs.docker.com/engine/reference/builder/
https://hub.docker.com/r/pytorch/pytorch/tags
https://hub.docker.com/

docker login
docker logout

docker pull pytorch/pytorch:1.13.1-cuda11.6-cudnn8-devel
docker build -t <username>/<reponame>:<tag> . [--no-cache]
docker push <username>/<reponame>:<tag>
docker tag <imageid> <username>/<reponame>:<tag>

docker image ls # 列出镜像
docker image rm <imagename> # 删除镜像

docker ps -a # 列出容器
docker rm <containername> # 删除容器
docker rm $(docker ps --filter status=exited -q) # 删除所有已停止的容器

docker exec -it <containername> bash # 进入正在运行的容器

interactive.sh:

#!/usr/bin/env bash

docker run --gpus=all -it --rm -e CUDA_VISIBLE_DEVICES --ipc=host -p 8888:8888 \
-v $PWD:/workspace/vits -v $PWD/AISHELL3:/workspace/vits/AISHELL3 -v $PWD/ImTong:/workspace/vits/ImTong \
--name mycontainer pytorch/pytorch:1.13.1-cuda11.6-cudnn8-devel bash

Dockerfile:

FROM pytorch/pytorch:1.13.1-cuda11.6-cudnn8-devel

RUN apt-get update && apt-get install -y libsndfile1
ADD requirements.txt .
RUN pip install -r requirements.txt

-------------↓ below is duplicated ↓---------------

一、安装

https://docs.docker.com/engine/install/ubuntu/

1.卸载旧版

sudo apt-get remove docker docker-engine docker.io containerd runc

2.install packages to allow apt to use a repository over HTTPS:

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

3.Add Docker’s official GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

验证:sudo apt-key fingerprint 0EBFCD88

4.set up the stable repository

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

5.Install Docker Engine

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

验证:sudo docker run hello-world
更新:sudo apt-get update

二、使用-上传自己的镜像

https://docs.docker.com/docker-hub/

1.注册Docker Hub

2.创一个仓库

3.在Ubuntu上登录

sudo docker login

4.创一个Dockerfile

cat > Dockerfile <<EOF
FROM busybox
CMD echo "Hello world! This is my first Docker image."
EOF

5.build your Docker image

sudo docker build -t <your_username>/my-first-repo .

最后那个点是Dockerfile的路径

6.查看本地有哪些镜像

sudo docker image ls

7.Test your docker image locally

sudo docker run <your_username>/my-first-repo

8. push your Docker image to Docker Hub

docker push <your_username>/my-first-repo

9.退出登录

docker logout

三、使用-使用镜像

https://github.com/docker/labs/blob/master/beginner/chapters/alpine.md

sudo docker pull alpine
sudo docker run alpine ls -l
sudo docker run alpine echo "hello from alpine"
sudo docker run -it alpine /bin/sh
exit
sudo docker ps
sudo docker ps -a

四、

posted on 2020-04-17 11:10  HolaWorld  阅读(1491)  评论(0编辑  收藏  举报

导航