问题 1: problem with installed package podman-2.0.5-5.module_el8.3.0+512+b3b58dca.x86_64 - package podman-2.0.5-5.module_el8.3.0+512+b3b58dca.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed - package podman-3.0.1-6.module_el8.4.0+781+acf4c33b.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed - package podman-3.0.1-7.module_el8.4.0+830+8027e1c4.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed - package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64 - package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-68.
rc92.module_el8.3.0+475+c50ce30b.x86_64 - package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64 - package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64 - package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64 - package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64 - cannot install the best candidate for the job - package runc-1.0.0-64.rc10.module_el8.4.0+522+66908d0c.x86_64 is filtered outby modular filtering - package runc-1.0.0-65.
rc10.module_el8.4.0+819+4afbd1d6.x86_64 is filtered outby modular filtering - package runc-1.0.0-70.rc92.module_el8.4.0+786+4668b267.x86_64 is filtered outby modular filtering - package runc-1.0.0-71.rc92.module_el8.4.0+833+9763146c.x86_64 is filtered outby modular filtering 问题 2: package podman-3.0.1-6.module_el8.4.0+781+acf4c33b.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed - package containerd.io-1.4.3-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64 - package containerd.io-1.4.3-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
- package containerd.io-1.4.3-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64 - package containerd.io-1.4.3-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64 - package docker-ce-3:20.10.7-3.el8.x86_64 requires containerd.io >= 1.4.1, but none of the providers can be installed - package containerd.io-1.4.3-3.2.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64 - package containerd.io-1.4.3-3.2.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64 - package containerd.io-1.4.3-3.2.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64 - package containerd.io-1.4.3-3.2.el8.x86_64 obsoletes runc provided
by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64 - package podman-catatonit-3.0.1-6.module_el8.4.0+781+acf4c33b.x86_64 requires podman = 3.0.1-6.module_el8.4.0+781+acf4c33b, but none of the providers can be installed - problem with installed package podman-catatonit-2.0.5-5.module_el8.3.0+512+b3b58dca.x86_64 - package podman-catatonit-3.0.1-7.module_el8.4.0+830+8027e1c4.x86_64 requires podman = 3.0.1-7.module_el8.4.0+830+8027e1c4, but none of the providers can be installed - package podman-3.0.1-7.module_el8.4.0+830+8027e1c4.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed - package containerd.io-1.4.3-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64 - package containerd.io-1.4.3-3.1.el8.x86_64 obsoletes runc provided by
runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64 - package containerd.io-1.4.3-3.2.el8.x86_64 conflicts with runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64 - package containerd.io-1.4.3-3.2.el8.x86_64 obsoletes runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64 - package containerd.io-1.4.4-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64 - package containerd.io-1.4.4-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64 - package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64 - package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64
- cannot install the best candidate for the job - package runc-1.0.0-64.rc10.module_el8.4.0+522+66908d0c.x86_64 is filtered outby modular filtering - package runc-1.0.0-65.rc10.module_el8.4.0+819+4afbd1d6.x86_64 is filtered outby modular filtering - package runc-1.0.0-70.rc92.module_el8.4.0+786+4668b267.x86_64 is filtered outby modular filtering - package runc-1.0.0-71.rc92.module_el8.4.0+833+9763146c.x86_64 is filtered outby modular filtering - package containerd.io-1.4.4-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64 - package
containerd.io-1.4.4-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64 - package containerd.io-1.4.4-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64 - package containerd.io-1.4.4-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64 - package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64 - package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64 - package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64 - package containerd.io-1.4.6-3.1
.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64 - package podman-catatonit-2.0.5-5.module_el8.3.0+512+b3b58dca.x86_64 requires podman = 2.0.5-5.module_el8.3.0+512+b3b58dca, but none of the providers can be installed - package podman-2.0.5-5.module_el8.3.0+512+b3b58dca.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed
这是由于docker和Podman冲突造成的,需要先卸载Podman:
yum erase podman buildah
2.2 在Win10中安装
Docker的运行,依赖linux的环境,官方提供了Docker Desktop for Windows,但是它需要安装Hyper-V,Hyper-V是微软开发的虚拟机,类似于 VMWare 或 VirtualBox,仅适用于 Windows 10。这个虚拟机一旦启用,QEMU、VirtualBox 或 VMWare Workstation 15 及以下版本将无法使用!如果你必须在电脑上使用其他虚拟机(例如开发 Android 应用必须使用的模拟器),请不要使用 Hyper-V!
我的电脑是win10家庭版,不能直接安装hyper-v,需要将下面的命令保存到cmd文件中:
pushd "%~dp0"
dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt
for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 20.04 f643c72bc252 5 weeks ago 72.9MB hello-world latest bf756fb1ae65 12 months ago 13.3kB
当前我本地只有刚才安装的两个镜像。
3.2 从镜像库中查找镜像
执行命令 docker search 镜像名称可以从docker镜像库中查找镜像。
$ docker search python NAME DESCRIPTION STARS OFFICIAL AUTOMATED python Python is an interpreted, interactive, objec… 5757 [OK] django Django is a free web application framework, … 1039 [OK] pypy PyPy is a fast, compliant alternative implem… 260 [OK] joyzoursky/python-chromedriver Python with Chromedriver, for running automa… 57 [OK]
nikolaik/python-nodejs Python with Node.js 57 [OK] arm32v7/python Python is an interpreted, interactive, objec… 53 circleci/python Python is an interpreted, interactive, objec… 42 centos/python-35-centos7 Platformfor building and running Python 3.5… 38 centos/python-36-centos7 Platformfor building and running Python 3.6… 30 hylang Hy is a Lisp dialect that translates express… 29 [OK] arm64v8/python Python is an interpreted, interactive, objec… 24 revolutionsystems/python Optimized Python Images 18 centos/python-27-centos7 Platformfor building and running Python 2.7… 17 bitnami/python Bitnami Python Docker Image 10 [OK] publicisworldwide/python-conda Basic Python environments with Conda. 6 [OK] d3fk/python_in_bottle Simple python:alpine completed by Bottle+Req… 5 [OK]
dockershelf/python Repository for docker images of Python. Test… 5 [OK] clearlinux/python Python programming interpreted language with… 4 i386/python Python is an interpreted, interactive, objec… 3 ppc64le/python Python is an interpreted, interactive, objec… 2 centos/python-34-centos7 Platformfor building and running Python 3.4… 2 amd64/python Python is an interpreted, interactive, objec… 1 ccitest/python CircleCI test images for Python 0 [OK] s390x/python Python is an interpreted, interactive, objec… 0 saagie/python Repo for python jobs 0
执行命令docker run即可启动容器,也就是创建某个镜像的实例。docker run命令非常复杂,可以先执行一个docker run --help来查看帮助:
$ docker run --help
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
Options: --add-host list Add a custom host-to-IP mapping (host:ip) -a, --attach list Attach to STDIN, STDOUT or STDERR --blkio-weight uint16 Block IO (relative weight), between 10and1000, or0to disable (default0) --blkio-weight-device list Block IO weight (relative device weight) (default []) --cap-add list Add Linux capabilities --cap-drop list Drop Linux capabilities --cgroup-parent stringOptional parent cgroup for the container --cidfile string Write the container ID to the file --cpu-period int Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota --cpu-rt-period int Limit CPU real-time period in microseconds --cpu-rt-runtime int Limit CPU real-time runtime in microseconds -c, --cpu-shares int CPU shares (relative weight) --cpus decimal Number of CPUs --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1) --cpuset-mems string MEMs in which to allow execution (0-3, 0,1) -d, --detach Run container in background and print container ID --detach-keys string Override the key sequence for detaching a container --device list Add a host device to the container --device-cgroup-rule list Add a rule to the cgroup allowed devices list --device-read-bps list Limit read rate (bytes per second) from
a device (default []) --device-read-iops list Limit read rate (IO per second) from a device (default []) --device-write-bps list Limit write rate (bytes per second) to a device (default []) --device-write-iops list Limit write rate (IO per second) to a device (default []) --disable-content-trust Skip image verification (defaulttrue) --dns list Setcustom DNS servers --dns-option list Set DNS options --dns-search list Setcustom DNS search domains --domainname string Container NIS domain name --entrypoint string Overwrite the default ENTRYPOINT of the image -e, --env list Set environment variables --env-file list Read in a file of environment variables --expose list Expose a port or a range of ports --gpus gpu-request GPU devices to add to the container ('all' to pass all GPUs) --group-add list Add additional groups tojoin --health-cmd string Command to
run to check health --health-interval duration Time between running the check (ms|s|m|h) (default0s) --health-retries int Consecutive failures needed to report unhealthy --health-start-period duration Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default0s) --health-timeout duration Maximum time to allow one check to run (ms|s|m|h) (default0s) --help Print usage -h, --hostname string Container host name --init Run an init inside the container that forwards signals and reaps processes -i, --interactive Keep STDIN open even ifnot attached --ip string IPv4 address (e.g., 172.30.100.104) --ip6 string IPv6 address (e.g., 2001:db8::33) --ipc string IPC mode to use --isolation string Container isolation technology --kernel-memory bytes Kernel memory limit -l, --label list Set meta data on a container --label-file list Read in a line delimited file of labels --link list Add link to another container --link-local-ip list Container IPv4/IPv6 link-local addresses --log-driver string Logging driver for
the container --log-opt list Log driver options --mac-address string Container MAC address (e.g., 92:d0:c6:0a:29:33) -m, --memory bytes Memory limit --memory-reservation bytes Memory soft limit --memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap --memory-swappiness int Tune container memory swappiness (0to100) (default-1) --mount mount Attach a filesystem mount to the container --name string Assign a name to the container --network network Connect a container to a network --network-alias list Add network-scoped aliasfor the container --no-healthcheck Disable any container-specified HEALTHCHECK --oom-kill-disable Disable OOM Killer --oom-score-adj int Tune host's OOM preferences (-1000 to 1000) --pid string PID namespaceto use --pids-limit int Tune container pids limit (set-1for unlimited) --platform stringSet platform if server is multi-platform capable --privileged Give extended privileges to this container
-p, --publish list Publish a container's port(s) to the host -P, --publish-all Publish all exposed ports to random ports --read-only Mount the container's root filesystem as read only --restart string Restart policy to apply when a container exits (default"no") --rm Automatically remove the container when it exits --runtime string Runtime to use for this container --security-opt list Security Options --shm-size bytes Size of /dev/shm --sig-proxy Proxy received signals to the process (defaulttrue) --stop-signal string Signal tostop a container (default"SIGTERM") --stop-timeout int Timeout (in seconds) tostop a container --storage-opt list Storage driver options for the container --sysctl map Sysctl options (default map[]) --tmpfs list Mount a tmpfs directory -t, --tty Allocate a pseudo-TTY --ulimit ulimit Ulimit options (default []) -u, --user string Username or UID (format: [:<group
|gid>]) --userns string User namespaceto use --uts string UTS namespaceto use -v, --volume list Bind mount a volume --volume-driver stringOptional volume driver for the container --volumes-from list Mount volumes from the specified container(s) -w, --workdir string Working directory inside the container
比如我们要执行python的shell,需要添加-it参数,即:docker run -it python:3.8
$ docker run -it python:3.8 Python 3.8.7 (default, Dec 222020, 18:46:25) [GCC 8.3.0] on linux Type "help", "copyright", "credits"or"license"for more information. >>>
docker run -v ~/docker_test:/docker_test -it -p 5001:5000 python:3.8 python /docker_test/hello.py
这样,就将容器的5000端口映射到了宿主机的5001端口,使用:
telnet 127.0.0.1 5001
即可与容器中的服务器进行连接。
4.4 容器管理
上面的服务运行之后,可以使用docker ps命令,查看运行中的容器:
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ec4c86b8a163 python:3.8"python /docker_test…"5 seconds ago Up 4 seconds 0.0.0.0:5000
->5000/tcp eager_wilson
$ docker run -it -p 8000:8000ws:1.0 python Python 3.8.7 (default, Dec 222020, 18:46:25) [GCC 8.3.0] on linux Type "help", "copyright", "credits"or"license"for more information. >>>
FROM ubuntu RUN apt update \ && apt install python3
然后运行:
dockerbuild-tpython:3.8-ubuntu .
这样,就生成了python:3.8-ubuntu镜像。
2、在python:3.8-ubuntu的基础上安装pip:
FROMpython:3.8-ubuntu RUNaptinstallpython3
然后运行:
dockerbuild-tpython:3.8-ubuntu-pip .
这样,就生成了python:3.8-ubuntu-pip镜像。
3、多阶段构建目标镜像:
FROM python:3.8-ubuntu-pip RUN pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy FROM python:3.8-ubuntu COPY --from=0 /usr/local/lib/python3.8/dist-packages//usr/local/lib/python3.8/dist-packages/
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello 1.001fe19111dc7 59 minutes ago 893MB python 3.8 f5041c8ae6b1 13 days ago 884MB ubuntu 20.04 f643c72bc252 5 weeks ago 72.9MB hello-world latest bf756fb1ae65 12 months ago 13.3kB