froobel
froobel

Reputation: 1

Containerfile entrypoint /bin/sh

I would like to create a container that runs only one shell. For this I have tried the following:

FROM alpine:latest
ENTRYPOINT ["/bin/sh"]

Unfortunately I don't get a shell when I start the container.

podman build -t $IMAGENAME .
podman run --name foobar $IMAGENAME
podman start -ai foobar

But if I start the container as follows it works

podman run --name foobar2 -ti $IMAGENAME /bin/sh
/ #

CTRL+C
podman start -ai foobar2
/ #

I had assumed that the entrypoint "/bin/sh" would directly execute a shell that you can work with.

Upvotes: 0

Views: 1491

Answers (2)

Hector Vido
Hector Vido

Reputation: 852

Your Containerfile is fine.

The problem is because your main command is a shell /bin/sh, a shell needs a pseudo-TTY or it will fail to start.

You can pass a pseudo-TTY with the --tty or -t option. Also, a good option is to use --interactive or -i to allow the main process to receive input.

All the commands below will work for you:

podman build -t $IMAGENAME .
# run (use CTRL + P + Q to exit)
podman run --name foobar -ti $IMAGENAME
# create + start
podman create --name foobar -ti $IMAGENAME
podman start foobar

This is not the case if the main command is something different than a shell like a webserver, as apache, for example.

Upvotes: 2

akathimi
akathimi

Reputation: 1581

The entrypoint needs to be a long lasting process. Using /bin/sh as the entrypoint, would cause the container to exit as soon as it starts.

Try using:

FROM alpine:latest
ENTRYPOINT ["sleep", "9999"]

Then you can exec into the container and run your commands.

Upvotes: 0

Related Questions