7

I am running the command

docker run php

and the terminal shows 'Interactive shell' and the docker image exits automatically. Here is the docker status

docker ps -a
"docker-php-entrypoi…"   Less than a second ago   Exited (0) 3 seconds ago 

4 Answers 4

10

Please try the following:

docker run -it --rm php bash
Sign up to request clarification or add additional context in comments.

2 Comments

This seems to work. Now that I run docker ps -a , I am able to see the container running. However, why does the container fail to start when I execute docker run php
honestly i'm not sure. in hub.docker.com/r/library/php, all examples require to use it as the base image, or run your own php script.
1

You need to tell docker run that it's an interactive process and allocate a tty for keyboard input, i.e.

$ docker run -it php
Interactive shell

php >

Comments

0

php needs -a to run in an interactive mode. -it is to keep a persistent session. To get an interactive directly, just run:

docker run -it --rm php php -a

Comments

0

Try:

docker run -it --name "Container name" -p "PHP port" -d "Docker image"

Example:

docker run -it --name php7.4.33 -p 9000:80 -d php:7.4.33 -a

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.