Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

start docker container interactively

Tags:

linux

docker

I have a very simple dockerfile with only one row, namely "FROM ubuntu". I created an image from this dockerfile by the command docker build -t ubuntu_ .

I know that I can create a new docker container from this image an run it interactively with the command docker run -it my_new_container

I can later start this new container with the command start my_new container

As I understand it, I should also be able to use this container it interactively by start -i my_new container

But, it does not work. It just runs and exits. I don't get to the container's command prompt as I do when I use run. What am I doing wrong?

like image 753
Henrik Leijon Avatar asked Aug 31 '20 00:08

Henrik Leijon


People also ask

How do I start a docker interactively container?

If you need to start an interactive shell inside a Docker Container, perhaps to explore the filesystem or debug running processes, use docker exec with the -i and -t flags. The -i flag keeps input open to the container, and the -t flag creates a pseudo-terminal that the shell can attach to.

How do I run a docker container in interactive background mode?

To run a docker container in the background or the detached mode from the terminal, you can use the docker run command followed by the -d flag (or detached flag) and followed by the name of the docker image you need to use in the terminal.

Which docker command launches an interactive shell?

Docker 'run' command to start an interactive BaSH session · GitHub.

How do I run a docker container with bin bash?

In order to start a Bash shell in a Docker container, execute the “docker exec” command with the “-it” option and specify the container ID as well as the path to the bash shell. If the Bash is part of your PATH, you can simply type “bash” and have a Bash terminal in your container.


Video Answer


2 Answers

If i understood correctly, you want to see the logs from container in terminal, same as when you run the image with docker run. If that's the case, then try with

docker start -a my_docker_container
like image 137
scovic Avatar answered Oct 16 '22 17:10

scovic


You can enter a running container with:

docker exec -it <container name> /bin/bash

example:

docker exec -it my_new_container /bin/bash

you can replace bash with sh if bash is not available in the container.

and if you need to explicitly use a UID , like root = UID 0, you can specify this:

docker exec -it -u 0 my_new_container /bin/bash

which will log you as root

like image 45
Ron Avatar answered Oct 16 '22 17:10

Ron