gpt4 book ai didi

Docker 容器以状态码 255 退出

转载 作者:行者123 更新时间:2023-12-04 18:39:32 25 4
gpt4 key购买 nike

docker -compose.yml

version: '3'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins
ports:
- "8080:8080"
volumes:
- "$PWD/jenkins_home:/var/jenkins_home"
networks:
- net
remote_host:
container_name: remote-host
image: remote-host
build:
context: ubuntu_container
networks:
- net
networks:
net:
Dockerfile
FROM ubuntu:20.04

RUN apt-get update && apt-get install -y openssh-server

RUN useradd -ms /bin/bash remote_user && \
echo 'remote_user:<password>' | chpasswd && \
mkdir /home/remote_user/.ssh && \
chmod 700 /home/remote_user/.ssh

COPY remote-key.pub /home/remote_user/.ssh/authorized_keys
RUN chown remote_user:remote_user -R /home/remote_user/.ssh && \
chmod 600 /home/remote_user/.ssh/authorized_keys

RUN ssh-keygen -A


CMD /usr/sbin/sshd -D
$ docker-compose build 的输出
Building remote_host
Step 1/7 : FROM ubuntu:20.04
---> 74435f89ab78
Step 2/7 : RUN apt-get update && apt-get install -y openssh-server
---> Using cache
---> dfaef48ff3df
Step 3/7 : RUN useradd -ms /bin/bash remote_user && echo 'remote_user:root123' | chpasswd && mkdir /home/remote_user/.ssh && chmod 700 /home/remote_user/.ssh
---> Using cache
---> 978387042c0f
Step 4/7 : COPY remote-key.pub /home/remote_user/.ssh/authorized_keys
---> Using cache
---> d5bc890cc4c1
Step 5/7 : RUN chown remote_user:remote_user -R /home/remote_user/.ssh && chmod 600 /home/remote_user/.ssh/authorized_keys
---> Using cache
---> 0a99e09c02aa
Step 6/7 : RUN ssh-keygen -A
---> Using cache
---> 8ed7cac699d5
Step 7/7 : CMD /usr/sbin/sshd -D
---> Running in de3b02ee7c10
Removing intermediate container de3b02ee7c10
---> 64eee00b5a0f
Successfully built 64eee00b5a0f
Successfully tagged remote-host:latest
$ docker-compose up -d 的输出
Recreating remote-host ... done
$ docker ps -a 的输出
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                         PORTS                               NAMES
2cb7f0c7f6b0 remote-host "/bin/sh -c '/usr/sb…" 13 seconds ago Exited (255) 9 seconds ago remote-host
我的容器已经构建并成功创建,但它仍然以状态码 255 退出。您能帮我解决这个问题吗

最佳答案

像这样使用你的 docker-compose 文件来映射你的主机 docker.sock:

version: '3'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins
privileged: true
ports:
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- "$PWD/jenkins_home:/var/jenkins_home"
networks:
- net
remote_host:
container_name: remote-host
image: remote-host
build:
context: ubuntu_container
networks:
- net
networks:
net:

关于Docker 容器以状态码 255 退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62640365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com