Docker
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.
- Run a Hello World
$docker run ubuntu /bin/echo 'Hello World'
docker run runs a container.
/bin/echo is the command to run inside the new container.
2. Run an interactive container
$docker run -t -i ubuntu /bin/bash
-t flag assigns a pseudo-tty or terminal inside the new container.
-i flag allows you to make an interactive connection by grabbing the standard input of the container.
/bin/bash launches a Bash shell inside our container.
- Start a daemonized Hello world
$docker run -d /bin/sh -c "While true; do echo hello world; sleep 1; done;"
-d flag runs the container in the background (to daemonize it)
The long string is called container ID, it uniquely identifies a container so we can work with it.
Docker automatically generates names for any containers started.
- To see what the docker is doing
$ docker logs docker_name
- To stop the docker
docker stop docker_name
- To remove a docker
$ docker rm acr434w3dmkf
Summary:
- docker ps -- list containers
- docker logs -- shows the standard output of the container
docker stop -- Stops running contains
To specify the port
$ docker run -d -p 8080:80 ubuntu
- Load balance between four application
$docker run -d --name web1 -p 8080:80 tutum/hello-world