Docker

De WikiMar
Dreceres ràpides: navegació, cerca

Basic commands

List all containers

docker ps -a

Delete container

docker rm happy_rosalind



Run an image

docker run -t -i 

→ can be detached with ^P^Q and reattached with docker attach

docker run -i

→ cannot be detached with ^P^Q; will disrupt stdin

docker run

→ cannot be detached with ^P^Q; can SIGKILL client; can reattach with docker attach

To detach the tty without exiting the shell, use the escape sequence

Ctrl+p + Ctrl+q


Run a container

docker start happy_rosalind


List all my images

docker images

Commit your container to a new named image

docker commit <container> <some_name>


Rename a container

docker rename oldname newname


Edit/examine the files of a container

docker exec -t -i mycontainer /bin/bash

Other methods: http://stackoverflow.com/questions/20813486/exploring-docker-containers-file-system

Docker Reference guide

https://docs.docker.com/engine/reference/commandline/

Basics

https://gist.github.com/dtuite/b595308c11e5bd251117

There are two programs:

   The docker daemon - a server process which manages all the containers
   The docker client - a remote control for the daemon

You can list the commands of the docker client by typing

docker

with no arguments.

You can use container images which have been created by other people. You find them online in the docker index. You can search for images using

docker search [keywords].

Container images are downloaded using

docker pull [image name].

Containers are unstarted by default. You can run commands in a container using the syntax:

docker run [image name] [command to run]

For example, we can install the program "ping" in the container with the command (note: the -y flag instructs apt-get to not ask us to confirm the changes we're about to make):

docker run learn/tutorial apt-get install -y ping

The changes we have made to the container are not yet saved. To save the container, we first need to find it's id:

docker ps -l

Once we have the first few chars of the id, we can save the container with a new image name using:

docker commit [id] [new image name]

We can now run the ping command on our container using:

docker run learn/ping ping www.google.com

We can use

docker ps

and

docker inspect [container id]

to learn about available containers.

We can share images using

docker push [image name.


Basics2

https://coreos.com/os/docs/latest/getting-started-with-docker.html


docker run -t -i ubuntu /bin/bash

The -t and -i flags allocate a pseudo-tty and keep stdin open even if not attached. This will allow you to use the container like a traditional VM as long as the bash prompt is running. Install Apache with apt-get update && apt-get install apache2. You’re probably wondering what address you can connect to in order to test that Apache was correctly installed…we’ll get to that after we commit the container.


To find the container ID, open another shell (so the container is still running) and read the ID using

docker ps.

The image name is in the format of username/name. We’re going to use coreos as our username in this example but you should sign up for a Docker.IO user account and use that instead. It’s important to note that you can commit using any username and image name locally, but to push an image to the public registry, the username must be a valid Docker.IO user account.

Commit the container with the container ID, your username, and the name apache:

docker commit 72d468f455ea coreos/apache

Containers

Install automatic virtualhosts

docker pull jwilder/nginx-proxy
docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock jwilder/nginx-proxy

Run any other container with the VIRTUAL_HOST

docker run -d -e VIRTUAL_HOST=domain1.com thiagomarini/apache-php
docker run -d -e VIRTUAL_HOST=domain2.com tomcat
docker run -d -t -i -p 8888:80 -e VIRTUAL_HOST=wikiservice.eu --name wikiservice.eu svendowideit/ubuntu-foswiki /bin/bash
docker run -d -t -i -p 8889:80 -e VIRTUAL_HOST=wakiga-hoki.de --name wakiga-hoki.de svendowideit/ubuntu-foswiki /bin/bash

Install Foswiki container

on Ubuntu

docker run -t -i -p 8888:80 svendowideit/ubuntu-foswiki /bin/bash then goto http://localhost:8888/foswiki


on Centos

docker build -t svendowideit/centos-foswiki .

run the image by:

docker run -p 8080:80 -i -t svendowideit/centos-foswiki /bin/bash


Install Postfix container

http://www.slideshare.net/dotCloud/postfix-tuto4

docker run -t -i ubuntu /bin/bash

Install with apt-get install postfix then exit with exit

docker ps -a
docker commit a363de70db9c sitoplex/postfix
docker run -i -p 25:25 -t sitoplex/postfix /bin/bash


Autostart containers at boot

sudo docker update --restart=always plex

https://docs.docker.com/engine/admin/start-containers-automatically/


Avoid container starting at boot automatically

docker update --restart=no my-container


See the current restart policy

docker inspect my-container

Look for RestartPolicy in the output. You can also use grep:

docker inspect my-container | grep RestartPolicy -A 3