Docker Quick Start


To run a command in Docker instance:

$ docker run ubuntu /bin/cat /proc/cpuinfo

To launch the docker instance shell:

$ docker run -i -t ubuntu /bin/bash

To persist docker:

Run the previous command, install all the applications that need to be available in Docker. Do NOT quit the shell. Open another terminal:

You now need to save the instance:

$ docker ps
CONTAINER ID        IMAGE                COMMAND                CREATED             STATUS              PORTS                     NAMES
984ebd17c204        subwiz/ruby:latest   /usr/bin/ruby -run -   40 minutes ago      Up 39 minutes       0.0.0.0:49154->9090/tcp   mad_shockley
d57022a848e6        subwiz/ruby:latest   /usr/bin/ruby -run -   42 minutes ago      Up 42 minutes       0.0.0.0:49153->9090/tcp   hopeful_meitner
1de12b4df413        ubuntu:14.04         /bin/bash              About an hour ago   Up About an hour                              berserk_goodall

You need to have [http://docs.docker.io/use/workingwithrepository/ created a login] for running the examples listed below.

To commit an instance:

$ docker commit 1de12b4df413 myname/kickassapp

To push app:

$ docker push myname/kickassapp

(It is not necessary to push the container to repository. Pushing is needed only for sharing with others.)

To run a docker container using the committed image:

$ docker run -i -t myname/kickassapp /bin/bash

This will have all the applications you installed previously.

For example, if you had installed Ruby, you can run the associated web-server:

$ docker run -d -p 9090:9191 myname/kickassapp \
  /usr/bin/ruby -run -e httpd . -p 9191

In the above command, 9090 is the host-port, and 9191 is the container port.

Run this command to validate which host-port is mapped to the docker instance:

$ docker ps
CONTAINER ID        IMAGE                COMMAND                CREATED             STATUS              PORTS                     NAMES
d29d92d55fef        subwiz/ruby:latest   /usr/bin/ruby -run -   7 seconds ago       Up 6 seconds        0.0.0.0:9090->9191/tcp   insane_sammet
1de12b4df413        ubuntu:14.04         /bin/bash              About an hour ago   Up About an hour                              berserk_goodall

You see the port mapping in the above command.

Docker Logs

$ docker logs <container-id>
Posted on Wed Jul 18 05:03:21 EDT 2018 by Subhash Chandran
container linux docker