Monday, September 26, 2016

Keep Docker Running in Background

Recently I've been playing with Docker. I'm sure that you have heard about it, but if not, here I write a brief description from Docker Website.
Docker containers wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries – anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.


That's it. If you've tried Vagrant, maybe you should take a look at Docker. What's difference between them? In short explanation, with Vagrant we usually build a VM per project. With this workflow, we may running out of memory and hard disk to store those VMs. How about Docker? Docker creating a new layer, named "container", a container is built based on "image". We could create multiple container based on same image. This could be easier to create and manage, based on my opinion. You could also get pre built-in images stored publicly on Docker Hub.

Return to the title of this article, I would like to share a little tips about how keep Docker running in background, even if our process/command (when we execute "docker run") is completed. For beginners (like me), usually we execute this command to create a container, according to example:
docker run ubuntu /bin/echo 'Hello world'
With this method, Docker will create container as we want, echoing 'Hello world', then stop. So, if we run command "docker ps" or maybe we want to ssh into it, docker will say that the container is not running. Try to run this command:
docker run -t -i ubuntu /bin/bash
Notice that I add "-t" option that will assigns a pseudo-tty or terminal inside the new container. With this method, we will get an interactive container that not stopped like before. This method is already mentioned at Docker Website. Nevertheless I will leave this note here, although may just become a note for myself. Hopefully it will be useful for others, too.

Related Articles

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. I read your Blog Your information is really awesome, Thanks for sharing information about Devops Online Training Hyderabad

    ReplyDelete