Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker run: how to run Ubuntu:16.04 without command?

Tags:

docker

I want to try out installing a program inside of Ubuntu in docker,

So I just run directly from the command prompt

docker run --name ubuntu_test ubuntu:16.04
docker exec -it ubuntu_test bash

but it doesn't work, it says container not running? how can I run the bash without setting up a dockerfile? (I tried using dockerfile, but it doesn't work because of interactive installer problem)

So I thought maybe directly install it from the bash could work.

like image 857
otong Avatar asked Dec 02 '22 10:12

otong


2 Answers

The problem is that your command doesn't keep the proccess alive nor does it keep it in the background so the container finishes its work and stops running. Its like docker run hello-world which prints some stuff and exits.

docker run -it --name ubuntu_test ubuntu:16.04 will work for you. The documentation explains:

For interactive processes (like a shell), you must use -i -t together in order to allocate a tty for the container process. -i -t is often written -it

An alternative would be to run the container in detached mode (-d) and give it a long running command so that it doesn't exit immediately:

docker run --name ubuntu_test -d ubuntu:16.04 sleep 300 docker exec -it ubuntu_test bash

like image 139
herm Avatar answered Dec 20 '22 13:12

herm


You are failing to start the container. Try this:

docker run -itd ubuntu:16.04 bash

-i, --interactive - Keep STDIN open even if not attached

-t, --tty - Allocate a pseudo-TTY

-d, --detach - Run container in background and print container ID

After this command list all your containers(docker ps):

enter image description here

Now you can attach to your running container and do some stuff:

docker exec -it 82d0bb7754e7 /bin/bash

(in this case, to indicate the container I used the ID, you can also use container name)

like image 44
Krzysztof Raciniewski Avatar answered Dec 20 '22 14:12

Krzysztof Raciniewski