Docker Community Forums

Share and learn in the Docker community.

How to build a centos7 docker image with a telnet server?

I am trying to build a centos7 docker image with telnet server. But I don’t know how to enable telnet server in it, because systemctl doesn’t work in docker.

When you do docker run with bash as the command, the init system (e.g. SystemD) doesn’t get started (nor does your start script, since the command you pass overrides the CMD in the Dockerfile). Try to change the command you use to /sbin/init , start the container in daemon mode with -d , and then look around in a shell using docker exec -it <container id> sh .

Thanks rahul1436!
But, when you run the container with /sbin/init, I am able to run the systemctl commands once I get into the shell of the container. However I am still not able to start the telnet service automatically when the container is launched. I had to login to shell and start manually. Using /sbin/init in my run command would still override the CMD in the Dockerfile right? Then how would I get to run the commnads under CMD in Dockefile to run automatically when I launch the container?

CMD systemctl start telnet.socket
could you add this in your Dockerfile and check. Please refer below link.