

In the next module, we’ll learn how to run a database in a container and connect it to our application. We also looked at naming our containers so they are more easily identifiable. We also took a look at managing containers by starting, stopping, and, restarting them. In this module, we took a look at running containers, publishing ports, and running containers in detached mode. That’s better! We can now easily identify our container based on the name. Run the following command in your terminal: Let’s start our image and make sure it is running correctly. The docker run command requires one parameter which is the name of the image. To run an image inside a container, we use the docker run command. Now that we have an image, we can run that image and see if our application is running correctly.Ī container is a normal operating system process except that this process is isolated and has its own file system, its own networking, and its own isolated process tree separated from the host. We created our image using the command docker build. In the previous module, we created our sample application and then we created a Dockerfile that we used to build an image. You might want to plan out a learning roadmap, to know what to learn next.įinally, if you want to avoid nasty gotchas, check out these 12 things I wish I knew about Docker when starting out.Work through the steps to build a Java image in Build your Java image.

Here are three articles which could help you get an overview, before you dive in:įirst, make sure you know about the most essential Docker basics. It looks like you’re just starting out with Docker. You can get the container id after executing the -d command, or you can look it up with docker ps. If you need to and perform one-off maintenance tasks. The above will start a bash session in the same container, which is great for taking a look around

You can either attach to it, or run an exec-command, such as: docker exec -ti CONTAINER_ID bash The same command from above would look like this: docker run -it -d busybox sh If you start a container, and need to detach from itįrequently, consider running it directly in the background, by starting it in “detached mode” with -d. You can attach to it later using docker attach, if you need to interact with the container more. Which keeps the container running but frees up your terminal. You turn interactive mode to daemon mode, You have to use two combinations, one after the other: ctrl+p followed by ctrl+q. The effect will be, as if you had started it with the -d flag in the first place. You can detach from an interactive Docker session without exiting the container. Then you can exit the shell, or the container might exit already.īut what if you want to keep the container running, but without occupying your terminal? Keep Your Container Running In The Background If there’s a non-shell process running, theĬombination is ctrl+c to interrupt it.

TL DR: press ctrl+c then ctrl+d - that means, keep the ctrl key pressed, type a c, and let go of ctrl. If you want to stop and exit the container, and are in an interactive, responsive shell - press ctrl+d to exit the session. See the "057e2d19b121" host name? Just Stopping the Container
