我们使用Docker compose和开源工具Dobi(GitHub - dnephin/dobi: A build automation tool for Docker applications)从一个Linux基础容器镜像(我们使用Almalinux),构建支持SSH两个容器,以及一个具备X11 forwarding的有Google chrome浏览器和Jetbain idea集成开发工具的容器。借鉴如此容器环境构建,可以很方便来搭建基于Windows下容器环境的Hadoop、Spark大数据教学开发的环境。可以参考本作者的另外几篇文章:Windows PC上创建大数据职业技能竞赛实验环境之一 / 七。
首先我们来看看什么是Docker compose。Docker compose 是用于定义和运行多容器 Docker 应用程序的工具。通过 Compose,您可以使用 YML 文件来配置应用程序需要的所有服务。然后,使用一个命令,就可以从 YML 文件配置中创建并启动所有服务。Windows下安装Docker Desktop,应该也有了Docker compose。
C:\MyDevz\dockerp>docker versionClient: Cloud integration: v1.0.29 Version: 20.10.21 API version: 1.41 Go version: go1.18.7 Git commit: baeda1f Built: Tue Oct 25 18:08:16 2022 OS/Arch: windows/amd64 Context: default Experimental: true Server: Docker Desktop 4.14.1 (91661) Engine: Version: 20.10.21 API version: 1.41 (minimum version 1.12) Go version: go1.18.7 Git commit: 3056208 Built: Tue Oct 25 18:00:19 2022 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.9 GitCommit: 1c90a442489720eec95342e1789ee8a5e1b9536f runc: Version: 1.1.4 GitCommit: v1.1.4-0-g5fd4c4d docker-init: Version: 0.19.0 GitCommit: de40ad0 C:\MyDevz\dockerp>docker-compose versionDocker Compose version v2.13.0
开源工具Dobi是一款Docker应用的自动化构建工具,用Dobi能保持项目高效组织,方便重构。他采用dobi.yaml来具体定义容器构建的资源与任务,并直接用dobi运行任务。Dobi可以通过github下载,具有windows和linux的不同程序。这里是windows下载链接:https://github.com/dnephin/dobi/releases/download/v0.15.0/dobi-windows.exe
一 构建支持SSH的容器镜像
创建项目目录,我的是C:\mydevz\dockerp。进入项目于目录。将下载好的dobi拷贝到目录,修改文件名。
dobi-windows.exe -> dobi.exe
1 在当前目录下创建Dockerfile。
FROM almalinux:latestMAINTAINER "LIU Gang from Hiroki Takeyama" # sshdRUN dnf -y install openssh-server openssh-clients; \ sed -i 's/^\(UsePAM yes\)/# \1/' /etc/ssh/sshd_config; \ ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N '' && \ ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' && \ ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N ''; \ sed -i 's/^#\(PermitRootLogin\) .*/\1 yes/' /etc/ssh/sshd_config; \ rm -f /run/nologin; \ dnf clean all; # 免密RUN sed -i 's/^#\(PubkeyAuthentication yes\)/\1/' /etc/ssh/sshd_config && \ echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config; \ ssh-keygen -t rsa -f /root/.ssh/id_rsa -P '' && \ cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys; # 基础应用RUN dnf -y install net-tools iproute procps;RUN dnf -y install bzip2 wget vim less;RUN dnf clean all; # 环境变量ENV TIMEZONE Asia/ShanghaiENV ROOT_PASSWORD ******* # root登录密码 RUN ln -fs /usr/share/zoneinfo/${TIMEZONE} /etc/localtime; \ echo "root:${ROOT_PASSWORD}" | chpasswd; \ touch /var/log/lastlog; # 暴露ssh端口EXPOSE 22 ENTRYPOINT ["/usr/sbin/init"]
在Dockerfile中通过ENTRYPOINT ["/usr/sbin/init"],让容器启动时启动systemd。
2 创建dobi.yaml。
meta: project: dockerp default: create image=almalinux: image: almalinux context: . dockerfile: Dockerfile tags: - 'S0.1'# - '{env.VERSION}' annotations: description: "Build the almalinux image" alias=create: tasks: ['almalinux:build'] annotations: description: "Create the images and containers" alias=clean: tasks: ['almalinux:rm'] annotations: description: "Remove the images and containers"
这时我们可以来创建新的容器镜像almalinux:S0.1。
C:\MyDevz\dockerp>dobi --versiondobi version 0.15.0 (build: 5c1481d, date: Sat Feb 27 19:05:16 UTC 2021) C:\MyDevz\dockerp>dobi listResources: almalinux Build the almalinux image clean Remove the images and containers create Create the images and containers C:\MyDevz\dockerp>dobi[WARN] Failed to load auth config: no docker configuration foundStep 1/12 : FROM almalinux:latest ---> 39f63d416992Step 2/12 : MAINTAINER "LIU Gang from Hiroki Takeyama" ---> Running in ecec068122c7Removing intermediate container ecec068122c7 ---> b84502db34adStep 3/12 : RUN dnf -y install openssh-server openssh-clients; sed -i 's/^\(UsePAM yes\)/# \1/' /etc/ssh/sshd_config; ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N '' && ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' && ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N ''; sed -i 's/^#\(PermitRootLogin\) .*/\1 yes/' /etc/ssh/sshd_config; rm -f /run/nologin; dnf clean all; ---> Running in 21c50551fb82AlmaLinux 8 - BaseOS 1.3 MB/s | 2.9 MB 00:02AlmaLinux 8 - AppStream 3.2 MB/s | 9.9 MB 00:03AlmaLinux 8 - Extras 7.5 kB/s | 18 kB 00:02Dependencies resolved.================================================================================ Package Arch Version Repository Size================================================================================Installing: openssh-clients x86_64 8.0p1-16.el8 baseos 668 k openssh-server x86_64 8.0p1-16.el8 baseos 492 kInstalling dependencies: libedit x86_64 3.1-23.20170329cvs.el8 baseos 102 k openssh x86_64 8.0p1-16.el8 baseos 522 k Transaction Summary================================================================================Install 4 Packages Total download size: 1.7 MInstalled size: 5.5 MDownloading Packages:(1/4): libedit-3.1-23.20170329cvs.el8.x86_64.rp 213 kB/s | 102 kB 00:00(2/4): openssh-8.0p1-16.el8.x86_64.rpm 792 kB/s | 522 kB 00:00(3/4): openssh-clients-8.0p1-16.el8.x86_64.rpm 947 kB/s | 668 kB 00:00(4/4): openssh-server-8.0p1-16.el8.x86_64.rpm 1.7 MB/s | 492 kB 00:00--------------------------------------------------------------------------------Total 947 kB/s | 1.7 MB 00:01Running transaction checkTransaction check succeeded.Running transaction testTransaction test succeeded.Running transaction Preparing : 1/1 Running scriptlet: openssh-8.0p1-16.el8.x86_64 1/4 Installing : openssh-8.0p1-16.el8.x86_64 1/4 Installing : libedit-3.1-23.20170329cvs.el8.x86_64 2/4 Installing : openssh-clients-8.0p1-16.el8.x86_64 3/4 Running scriptlet: openssh-server-8.0p1-16.el8.x86_64 4/4 Installing : openssh-server-8.0p1-16.el8.x86_64 4/4 Running scriptlet: openssh-server-8.0p1-16.el8.x86_64 4/4 Verifying : libedit-3.1-23.20170329cvs.el8.x86_64 1/4 Verifying : openssh-8.0p1-16.el8.x86_64 2/4 Verifying : openssh-clients-8.0p1-16.el8.x86_64 3/4 Verifying : openssh-server-8.0p1-16.el8.x86_64 4/4 Installed: libedit-3.1-23.20170329cvs.el8.x86_64 openssh-8.0p1-16.el8.x86_64 openssh-clients-8.0p1-16.el8.x86_64 openssh-server-8.0p1-16.el8.x86_64 Complete!Generating public/private dsa key pair.Your identification has been saved in /etc/ssh/ssh_host_ed25519_key.Your public key has been saved in /etc/ssh/ssh_host_ed25519_key.pub.The key fingerprint is:SHA256:M6RQtXJ0ZIUQFTmr4L6VESV/a5o6M+WykpkiJ+cIMoc root@21c50551fb82The key's randomart image is:+---[DSA 1024]----+| ..*=B=. || . . B+ || . . = .o. || ..= ... . || ...S. o || . . .=.+ ||E . . +ooo ||.+o.+ *.=.. || .*...oo* |+----[SHA256]-----+28 files removedRemoving intermediate container 21c50551fb82 ---> 587e9b935679Step 4/12 : RUN sed -i 's/^#\(PubkeyAuthentication yes\)/\1/' /etc/ssh/sshd_config && echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config; ssh-keygen -t rsa -f /root/.ssh/id_rsa -P '' && cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys; ---> Running in aa037c31e575Generating public/private rsa key pair.Created directory '/root/.ssh'.Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:SHA256:z6FY6ztEAvyZWRHe+iLF6pNy3CVFsancUCS81wLcYlA root@aa037c31e575The key's randomart image is:+---[RSA 3072]----+| . .=E=+. || o .B+oo || o *o=+. || *oo=+ . || oSoo. || =o*.. || .+++o+ || ..=oo. || o..oo |+----[SHA256]-----+Removing intermediate container aa037c31e575 ---> 36c28e11a985Step 5/12 : RUN dnf -y install net-tools iproute procps; ---> Running in a27cd3468aa5AlmaLinux 8 - BaseOS 590 kB/s | 2.9 MB 00:04AlmaLinux 8 - AppStream 3.1 MB/s | 9.9 MB 00:03AlmaLinux 8 - Extras 11 kB/s | 18 kB 00:01Dependencies resolved.================================================================================ Package Architecture Version Repository Size================================================================================Installing: iproute x86_64 5.18.0-1.el8 baseos 807 k net-tools x86_64 2.0-0.52.20160912git.el8 baseos 321 k procps-ng x86_64 3.3.15-9.el8 baseos 328 kInstalling dependencies: libbpf x86_64 0.5.0-1.el8 baseos 136 k libmnl x86_64 1.0.4-6.el8 baseos 30 k psmisc x86_64 23.1-5.el8 baseos 150 kTransaction Summary================================================================================Install 6 PackagesTotal download size: 1.7 MInstalled size: 5.0 MDownloading Packages:(1/6): libmnl-1.0.4-6.el8.x86_64.rpm 88 kB/s | 30 kB 00:00(2/6): libbpf-0.5.0-1.el8.x86_64.rpm 281 kB/s | 136 kB 00:00(3/6): net-tools-2.0-0.52.20160912git.el8.x86_6 937 kB/s | 321 kB 00:00(4/6): iproute-5.18.0-1.el8.x86_64.rpm 1.1 MB/s | 807 kB 00:00(5/6): procps-ng-3.3.15-9.el8.x86_64.rpm 1.5 MB/s | 328 kB 00:00(6/6): psmisc-23.1-5.el8.x86_64.rpm 926 kB/s | 150 kB 00:00--------------------------------------------------------------------------------Total 510 kB/s | 1.7 MB 00:03Running transaction checkTransaction check succeeded.Running transaction testTransaction test succeeded.Running transaction Preparing : 1/1 Installing : psmisc-23.1-5.el8.x86_64 1/6 Installing : libmnl-1.0.4-6.el8.x86_64 2/6 Running scriptlet: libmnl-1.0.4-6.el8.x86_64 2/6 Installing : libbpf-0.5.0-1.el8.x86_64 3/6 Installing : iproute-5.18.0-1.el8.x86_64 4/6 Installing : procps-ng-3.3.15-9.el8.x86_64 5/6 Installing : net-tools-2.0-0.52.20160912git.el8.x86_64 6/6 Running scriptlet: net-tools-2.0-0.52.20160912git.el8.x86_64 6/6 Verifying : iproute-5.18.0-1.el8.x86_64 1/6 Verifying : libbpf-0.5.0-1.el8.x86_64 2/6 Verifying : libmnl-1.0.4-6.el8.x86_64 3/6 Verifying : net-tools-2.0-0.52.20160912git.el8.x86_64 4/6 Verifying : procps-ng-3.3.15-9.el8.x86_64 5/6 Verifying : psmisc-23.1-5.el8.x86_64 6/6Installed: iproute-5.18.0-1.el8.x86_64 libbpf-0.5.0-1.el8.x86_64 libmnl-1.0.4-6.el8.x86_64 net-tools-2.0-0.52.20160912git.el8.x86_64 procps-ng-3.3.15-9.el8.x86_64 psmisc-23.1-5.el8.x86_64Complete!Removing intermediate container a27cd3468aa5 ---> 77d12e5c28f6Step 6/12 : RUN dnf -y install bzip2 wget vim less; ---> Running in 2a473b8ea2acLast metadata expiration check: 0:00:07 ago on Fri Dec 2 07:35:10 2022.Package less-530-1.el8.x86_64 is already installed.Dependencies resolved.================================================================================ Package Arch Version Repository Size================================================================================Installing: bzip2 x86_64 1.0.6-26.el8 baseos 60 k vim-enhanced x86_64 2:8.0.1763-19.el8_6.4 appstream 1.4 M wget x86_64 1.19.5-10.el8 appstream 733 kInstalling dependencies: gpm-libs x86_64 1.20.7-17.el8 appstream 38 k libmetalink x86_64 0.1.3-7.el8 baseos 32 k libpsl x86_64 0.20.2-6.el8 baseos 61 k publicsuffix-list-dafsa noarch 20180723-1.el8 baseos 56 k vim-common x86_64 2:8.0.1763-19.el8_6.4 appstream 6.3 M vim-filesystem noarch 2:8.0.1763-19.el8_6.4 appstream 49 k which x86_64 2.21-18.el8 baseos 48 kTransaction Summary================================================================================Install 10 PackagesTotal download size: 8.8 MInstalled size: 33 MDownloading Packages:(1/10): libmetalink-0.1.3-7.el8.x86_64.rpm 86 kB/s | 32 kB 00:00(2/10): libpsl-0.20.2-6.el8.x86_64.rpm 148 kB/s | 61 kB 00:00(3/10): bzip2-1.0.6-26.el8.x86_64.rpm 142 kB/s | 60 kB 00:00(4/10): which-2.21-18.el8.x86_64.rpm 388 kB/s | 48 kB 00:00(5/10): publicsuffix-list-dafsa-20180723-1.el8. 315 kB/s | 56 kB 00:00(6/10): gpm-libs-1.20.7-17.el8.x86_64.rpm 298 kB/s | 38 kB 00:00(7/10): vim-filesystem-8.0.1763-19.el8_6.4.noar 308 kB/s | 49 kB 00:00(8/10): wget-1.19.5-10.el8.x86_64.rpm 1.8 MB/s | 733 kB 00:00(9/10): vim-enhanced-8.0.1763-19.el8_6.4.x86_64 2.1 MB/s | 1.4 MB 00:00(10/10): vim-common-8.0.1763-19.el8_6.4.x86_64. 4.9 MB/s | 6.3 MB 00:01--------------------------------------------------------------------------------Total 2.0 MB/s | 8.8 MB 00:04Running transaction checkTransaction check succeeded.Running transaction testTransaction test succeeded.Running transaction Preparing : 1/1 Installing : vim-filesystem-2:8.0.1763-19.el8_6.4.noarch 1/10 Installing : vim-common-2:8.0.1763-19.el8_6.4.x86_64 2/10 Installing : gpm-libs-1.20.7-17.el8.x86_64 3/10 Running scriptlet: gpm-libs-1.20.7-17.el8.x86_64 3/10 Installing : which-2.21-18.el8.x86_64 4/10 Installing : publicsuffix-list-dafsa-20180723-1.el8.noarch 5/10 Installing : libpsl-0.20.2-6.el8.x86_64 6/10 Installing : libmetalink-0.1.3-7.el8.x86_64 7/10 Installing : wget-1.19.5-10.el8.x86_64 8/10 Running scriptlet: wget-1.19.5-10.el8.x86_64 8/10 Installing : vim-enhanced-2:8.0.1763-19.el8_6.4.x86_64 9/10 Installing : bzip2-1.0.6-26.el8.x86_64 10/10 Running scriptlet: bzip2-1.0.6-26.el8.x86_64 10/10 Running scriptlet: vim-common-2:8.0.1763-19.el8_6.4.x86_64 10/10 Verifying : bzip2-1.0.6-26.el8.x86_64 1/10 Verifying : libmetalink-0.1.3-7.el8.x86_64 2/10 Verifying : libpsl-0.20.2-6.el8.x86_64 3/10 Verifying : publicsuffix-list-dafsa-20180723-1.el8.noarch 4/10 Verifying : which-2.21-18.el8.x86_64 5/10 Verifying : gpm-libs-1.20.7-17.el8.x86_64 6/10 Verifying : vim-common-2:8.0.1763-19.el8_6.4.x86_64 7/10 Verifying : vim-enhanced-2:8.0.1763-19.el8_6.4.x86_64 8/10 Verifying : vim-filesystem-2:8.0.1763-19.el8_6.4.noarch 9/10 Verifying : wget-1.19.5-10.el8.x86_64 10/10Installed: bzip2-1.0.6-26.el8.x86_64 gpm-libs-1.20.7-17.el8.x86_64 libmetalink-0.1.3-7.el8.x86_64 libpsl-0.20.2-6.el8.x86_64 publicsuffix-list-dafsa-20180723-1.el8.noarch vim-common-2:8.0.1763-19.el8_6.4.x86_64 vim-enhanced-2:8.0.1763-19.el8_6.4.x86_64 vim-filesystem-2:8.0.1763-19.el8_6.4.noarch wget-1.19.5-10.el8.x86_64 which-2.21-18.el8.x86_64Complete!Removing intermediate container 2a473b8ea2ac ---> a6a8b4c3d7b3Step 7/12 : RUN dnf clean all; ---> Running in a015ca5f3ef128 files removedRemoving intermediate container a015ca5f3ef1 ---> efa368ed57d9Step 8/12 : ENV TIMEZONE Asia/Shanghai ---> Running in a032f353b151Removing intermediate container a032f353b151 ---> bbadda4a968bStep 9/12 : ENV ROOT_PASSWORD 1234509876 ---> Running in 02461ca03242Removing intermediate container 02461ca03242 ---> c022971e8c5cStep 10/12 : RUN ln -fs /usr/share/zoneinfo/${TIMEZONE} /etc/localtime; echo "root:${ROOT_PASSWORD}" | chpasswd; touch /var/log/lastlog; ---> Running in a87f93c9a541Removing intermediate container a87f93c9a541 ---> eb9dbb2e914dStep 11/12 : EXPOSE 22 ---> Running in 1911fa190244Removing intermediate container 1911fa190244 ---> 0f514ea28051Step 12/12 : ENTRYPOINT ["/usr/sbin/init"] ---> Running in 2fabea46bc80Removing intermediate container 2fabea46bc80 ---> 2a489e613a1cSuccessfully built 2a489e613a1cSuccessfully tagged almalinux:S0.1[image:build almalinux] almalinux Created
查看构建的镜像。
C:\MyDevz\dockerp>docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEalmalinux S0.1 2a489e613a1c 2 hours ago 309MB
3 创建docker-compose.yaml。
version: '3' services: almalinux1: image: "almalinux:S0.1" container_name: almalinux1 hostname: almalinux1 ports: - "2221:22" #restart: unless-stopped networks: network: ipv4_address: 172.99.99.11 extra_hosts: - "almalinux2:172.99.99.12" privileged: true almalinux2: image: "almalinux:S0.1" container_name: almalinux2 hostname: almalinux2 ports: - "2222:22" #restart: unless-stopped networks: network: ipv4_address: 172.99.99.12 extra_hosts: - "almalinux1:172.99.99.11" privileged: true networks: network: driver: bridge ipam: config: - subnet: 172.99.99.0/24 gateway: 172.99.99.1
4 修改dobi.yaml,dobi的任务是用docker-compose.yaml启动镜像,产生两个容器,即这里的compose=almalinux-double,他依赖镜像almalinux。
meta: project: dockerp default: create image=almalinux: image: almalinux context: . dockerfile: Dockerfile tags: - 'S0.1'# - '{env.VERSION}' annotations: description: "Build the almalinux image" compose=almalinux-double: files: - docker-compose.yml project: 'almalinuxs' depends: [almalinux, almalinux_chrome-idea] annotations: description: "Build the almalinux double" alias=create: tasks: ['almalinux:build', 'almalinux-double:detach'] annotations: description: "Create the images and containers" alias=clean: tasks: ['almalinux-double:down', 'almalinux:rm'] annotations: description: "Remove the images and containers"
重新运行dobi。
C:\MyDevz\dockerp>dobi.........[compose:detach almalinux-double] docker-compose.yml project upfailed to get console mode for stdin: The handle is invalid.[+] Running 4/4 - Network almalinuxs_network Created 0.0s - Container almalinux2 Started 0.8s - Container almalinux1 Started 1.1s[compose:detach almalinux-double] docker-compose.yml Done[alias:run create] Done
查看镜像和容器。
C:\MyDevz\dockerp>docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEalmalinux S0.1 2a489e613a1c 2 hours ago 309MB C:\MyDevz\dockerp>docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf38e4b8f92b0 almalinux:S0.1 "/usr/sbin/init" 2 hours ago Up 2 hours 0.0.0.0:2222->22/tcp almalinux219fda9f16141 almalinux:S0.1 "/usr/sbin/init" 2 hours ago Up 2 hours 0.0.0.0:2221->22/tcp almalinux1
ssh进入容器。
二 构建运行Google chrome和Jetbrain idea镜像
在前述SSH镜像的基础上,让我们进一步构建构建运行Google chrome和Jetbrain idea镜像。
1 创建Dockerfile_chrome-idea
FROM almalinux:S0.1MAINTAINER "LIU Gang" # X11 forwardRUN dnf -y install xorg-x11-xauth && \ sed -i 's/^#\(AllowTcpForwarding yes\)/\1/' /etc/ssh/sshd_config # chromeRUN dnf -y install mesa-dri-drivers mesa-libGL mesa-libEGL wqy-microhei-fontsADD google-chrome.repo /etc/yum.repos.d/ADD linux_signing_key.pub /tmp/RUN rpm --import linux_signing_key.pubADD google-chrome-stable_current_x86_64.rpm /tmp/RUN dnf -y localinstall /tmp/google-chrome-stable_current_x86_64.rpm && \ echo "export DBUS_SESSION_BUS_ADDRESS=$(dbus-daemon --session --fork --print-address 1)" >> /root/.bashrc && \ echo "alias google-chrome='google-chrome --no-sandbox --disable-dev-shm-usage --disable-gpu --disable-software-rasterizer --ignore-certificate-errors'" >> /root/.bashrc && \ rm -f /tmp/google-chrome-stable_current_x86_64.rpm && \ rm -f /tmp/linux_signing_key.pub # idea ADD ideaIC-2022.3.tar.gz /tmp/WORKDIR /tmpRUN mv idea-IC-223.7571.182 /usr/local && \ ln -sf /usr/local/idea-IC-223.7571.182/bin/idea.sh /usr/local/bin/idea.sh && \ rm -rf /tmp/idea-IC-223.7571.182 RUN dnf clean all #EXPOSE 22 ENTRYPOINT ["/usr/sbin/init"]#CMD ["/usr/sbin/sshd", "-D", "-e"]
其中,添加google-chrome.repo文件。
[google-chrome]name=google-chromebaseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearchenabled=1gpgcheck=0gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
预先下载 linux_signing_key.pub(https://dl.google.com/linux/linux_signing_key.pub)和google-chrome-stable_current_x86_64.rpm(https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm)以及ideaIC-2022.3.tar.gz(https://download.jetbrains.com/idea/ideaIC-2022.3.tar.gz)。
2 修改docker-compose.yaml,增加运行almalinux_chrome-idea:S0.2
version: '3' services: almalinux1: image: "almalinux:S0.1" container_name: almalinux1 hostname: almalinux1 ports: - "2221:22" #restart: unless-stopped networks: network: ipv4_address: 172.99.99.11 extra_hosts: - "almalinux2:172.99.99.12" privileged: true almalinux2: image: "almalinux:S0.1" container_name: almalinux2 hostname: almalinux2 ports: - "2222:22" #restart: unless-stopped networks: network: ipv4_address: 172.99.99.12 extra_hosts: - "almalinux1:172.99.99.11" privileged: true almalinux_chrome-idea: image: "almalinux_chrome-idea:S0.2" container_name: almalinux_chrome-idea hostname: almalinux-dev ports: - "2223:22" #restart: unless-stopped networks: network: ipv4_address: 172.99.99.19 extra_hosts: - "almalinux1:172.99.99.11" - "almalinux2:172.99.99.12" privileged: true networks: network: driver: bridge ipam: config: - subnet: 172.99.99.0/24 gateway: 172.99.99.1
3 修改dobi.yaml。新镜像almalinux_chrome-idea:S0.2要依赖镜像almalinux:S0.1,并调用docker-compose.yaml启动镜像,产生运行的容器。
meta: project: dockerp default: create image=almalinux: image: almalinux context: . dockerfile: Dockerfile tags: - 'S0.1'# - '{env.VERSION}' annotations: description: "Build the almalinux image" image=almalinux_chrome-idea: image: almalinux_chrome-idea context: . dockerfile: Dockerfile_chrome-idea depends: [almalinux] tags: - 'S0.2'# - '{env.VERSION}' annotations: description: "Build almalinux chrome & idea image" compose=almalinux-double: files: - docker-compose.yml project: 'almalinuxs' depends: [almalinux, almalinux_chrome-idea] annotations: description: "Build the almalinux double" alias=create: tasks: ['almalinux:build', 'almalinux_chrome-idea:build', 'almalinux-double:detach'] annotations: description: "Create the images and containers" alias=clean: tasks: ['almalinux-double:down', 'almalinux_chrome-idea:rm', 'almalinux:rm'] annotations: description: "Remove the images and containers"
查看结果。
C:\MyDevz\dockerp>docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEalmalinux_chrome-idea S0.2 2e24aaaaacfb 2 hours ago 6.94GBalmalinux S0.1 2a489e613a1c 2 hours ago 309MB C:\MyDevz\dockerp>docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf38e4b8f92b0 almalinux:S0.1 "/usr/sbin/init" 2 hours ago Up 2 hours 0.0.0.0:2222->22/tcp almalinux219fda9f16141 almalinux:S0.1 "/usr/sbin/init" 2 hours ago Up 2 hours 0.0.0.0:2221->22/tcp almalinux1a8f60a1d85b4 almalinux_chrome-idea:S0.2 "/usr/sbin/init" 2 hours ago Up 2 hours 0.0.0.0:2223->22/tcp almalinux_chrome-idea
开启ssh终端。
原网址: 访问
创建于: 2023-04-19 12:44:52
目录: default
标签: 无
未标明原创文章均为采集,版权归作者所有,转载无需和我联系,请注明原出处,南摩阿彌陀佛,知识,不只知道,要得到
最新评论