You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Docker容器构建成功后以状态码255退出的问题排查求助

Troubleshooting Remote-Host Container Exiting with Status Code 255

Let's figure out why your remote-host container is crashing immediately after startup. Here's a step-by-step approach to diagnose and fix the issue:

1. First, Grab Detailed Error Logs

The most important first step is to check what's causing the SSH daemon to fail. Run this command to pull the container's startup logs:

docker logs remote-host

This will show you the exact error message from the sshd process, which will point us straight to the root problem.

2. Common Causes & Fixes

Based on your Dockerfile and setup, these are the most likely culprits:

Issue 1: SSH Daemon Configuration Gaps

Ubuntu 20.04's default sshd_config has some restrictive settings that might block the service from starting properly. Let's explicitly enable the authentication methods you need by adding these lines to your Dockerfile (before the CMD step):

# Ensure SSH allows both password and public key authentication
RUN echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
RUN echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config

Issue 2: Invalid or Missing Public Key

Double-check that the remote-key.pub file exists in your ubuntu_container directory (the build context specified in your docker-compose.yml). If this file is missing or contains a malformed public key, the SSH daemon might fail to initialize, or your remote_user won't be able to authenticate.

Issue 3: Enable Verbose SSH Logging

Modify the CMD in your Dockerfile to run sshd in verbose mode—this will give you way more detail about what's going wrong during startup:

CMD /usr/sbin/sshd -D -e

The -e flag sends debug logs to the container's stdout, making it easier to spot subtle issues.

3. Re-Build & Test

After making any changes, re-build and restart your containers:

docker-compose down
docker-compose build
docker-compose up -d

Then check the container status again with docker ps -a. If it stays running, you've fixed the issue! If not, re-run docker logs remote-host to get the new error details and iterate.

内容的提问来源于stack exchange,提问作者user3497146

火山引擎 最新活动