Docker Community Forums

Share and learn in the Docker community.

How to Change an Image ssh at start up

Hello there,

I want to create a template ubuntu image for my self.

I start with this image and add what I need.

But I get in struggle, when I want to activate ssh on start up.

How/where could I edit the dockerfile, after the pulling?

Enabling SSH

Baseimage-docker disables the SSH server by default. Add the following to your Dockerfile to enable it:

RUN rm -f /etc/service/sshd/down

# Regenerate SSH host keys. baseimage-docker does not contain any, so you
# have to do that yourself. You may also comment out this instruction; the
# init system will auto-generate one during boot.
RUN /etc/my_init.d/00_regen_ssh_host_keys.sh

Alternatively, to enable sshd only for a single instance of your container, create a folder with a startup script. The contents of that should be

### In myfolder/enable_ssh.sh (make sure this file is chmod +x):
#!/bin/sh
rm -f /etc/service/sshd/down
ssh-keygen -P "" -t dsa -f /etc/ssh/ssh_host_dsa_key

Then, you can start your container with

docker run -d -v `pwd`/myfolder:/etc/my_init.d my/dockerimage

Edit;
I needt to make a new Dockerfile and build a new image

You shouldn’t do it after pulling, but you should create your own Dockerfile. Then, when building that, Docker will pull the base image for you automatically. (It doesn’t hurt to pull it manually. But pulling is only going to put it in your local cache and is not going to give you some Dockerfile that you can then edit. You’ll need to create it.)

So, given the part you quoted above (for which I don’t know if it’s complete), create a file called Dockerfile (without a file extension), and make that hold something like:

FROM phusion/baseimage:focal-1.0.0

RUN rm -f /etc/service/sshd/down

# Regenerate SSH host keys. baseimage-docker does not contain any, so you
# have to do that yourself. You may also comment out this instruction; the
# init system will auto-generate one during boot.
RUN /etc/my_init.d/00_regen_ssh_host_keys.sh

Save the file, build and “tag” it from the same directory using docker build -t my-ubuntu . and run it using docker run my-ubuntu or something similar.

2 Likes

Thx

It is working now.
I managed to install everything in advance.

Greetings