Bibily Bob Joe
Bibily Bob Joe

Reputation: 71

Is there a point in Docker start?

So, is there a point in the command "start"? like in "docker start -i albineContainer".

If I do this, I can't really do anything with the albine inside the container, I would have to do a run and create another container with the "-it" command and "sh" after (or "/bin/bash", don't remember it correctly right now).

Is that how it will go most of the times? delete and rebuilt containers and do the command "-it" if you want to do stuff in them? or would it more depend on the Dockerfile, how you define the cmd.

New to Docker in general and trying to understand the basics on how to use it. Thanks for the help.

Upvotes: 0

Views: 321

Answers (2)

David Maze
David Maze

Reputation: 159733

You almost never use docker start. It's only possible to use it in two unusual circumstances:

  1. If you've created a container with docker create, then docker start will run the process you named there. (But it's much more common to use docker run to do both things together.)

  2. If you've stopped a container with docker stop, docker start will run its process again. (But typically you'll want to docker rm the container once you've stopped it.)

Your question and other comments hint at using an interactive shell in an unmodified Alpine container. Neither is a typical practice. Usually you'll take some complete application and its dependencies and package it into an image, and docker run will run that complete packaged application. Tutorials like Docker's Build and run your image go through this workflow in reasonable detail.

My general day-to-day workflow involves building and testing a program outside of Docker. Once I believe it works, then I run docker build and docker run, and docker rm the container once I'm done. I rarely run docker exec: it is a useful debugging tool but not the standard way to interact with a process. docker start isn't something I really ever run.

Upvotes: 1

gkpln3
gkpln3

Reputation: 1499

Running docker run/exec with -it means you run the docker container and attach an interactive terminal to it.

Note that you can also run docker applications without attaching to them, and they will still run in the background.

Docker allows you to run a program (which can be bash, but does not have to be) in an isolated environment.

For example, try running the jenkins docker image: https://hub.docker.com/_/jenkins. this will create a container, without you having attach to it, and you would still be able to use it.

You can also attach to an existing, running container by using docker exec -it [container_name] bash.

You can also use docker logs to peek at the stdout of a certain docker container, without actually attaching to its shell interactively.

Upvotes: 1

Related Questions