Stav Alfi
Stav Alfi

Reputation: 13953

Nothing happends when running docker attach

docker pull httpd
..
docker run -d --name MyWebServer httpd
..
docker attach MyWebServer
(nothing printed here - so I press enter + ls)
ls
(nothing printed here - so I press enter multiple times and still nothing..)

When I try to do the same thing with ubuntu image, it works. Why it isn't working here?

Upvotes: 2

Views: 269

Answers (2)

Mike Doe
Mike Doe

Reputation: 17604

Have you read the docs? The attach returns any messages that the container produces. I bet you wanted to do the exec instead.

It’s either

docker exec -it container_name_or_id bash 

or

docker-compose exec service_name bash 

if you use the docker-compose app.

You can execute any command (unless the container has no fixed entrypoint), for instance

docker exec container ls /

Upvotes: 1

Robert
Robert

Reputation: 36823

The difference is the running process. With Ubuntu, you are being attached to the sh. With httpd you are being attached to the apache main process, which is not a shell.

Do this instead of attach:

docker exec -it MyWebServer sh

With that, you are launching a shell inside the same container that runs apache process.

Upvotes: 2

Related Questions