Skip to content

Instantly share code, notes, and snippets.

@vallard
Last active June 11, 2020 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vallard/5a7bcebb912e673ed60a to your computer and use it in GitHub Desktop.
Save vallard/5a7bcebb912e673ed60a to your computer and use it in GitHub Desktop.
Docker Webcast Notes

Docker Webcast notes for Jan 20th, 2015

Docker installation

Basic Ubuntu

sudo apt-get -y update
sudo apt-get -y install openssh-server

Install Docker

see: [https://docs.docker.com/installation/ubuntulinux/](Docker Documentation)

sudo apt-get -y install docker.io
sudo ln -s /usr/bin/docker.io /usr/local/bin/docker
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
sudo sh -c "echo deb https://get.docker.com/ubuntu docker main\
> /etc/apt/sources.list.d/docker.list"
sudo apt-get update
sudo apt-get install lxc-docker

Need a proxy?

Edit /etc/default/docker

export http_proxy="http://proxy.example.com:3128"

Test Docker

docker pull busybox
docker pull ubuntu
docker pull nginx
docker images

Checkout the Docker hub, or run docker search for images you want.

Now let's run some images:

docker run -i -t --rm ubuntu /bin/bash
docker run -it --rm -p 80:80 nginx /bin/bash
# service nginx start

Now you can point a browser to the webserver (eg: http://172.20.200.20) and see a default nginx server.

Notice when we exit the image, we are done. The webserver goes away. We might want to run this and disconnect.
Let's try it like this:

docker run -P -d nginx

The webserver should be up, but its not!

docker ps 

and we can see what port we are mapped to. We connect to this: (e.g: http://172.20.200.20:49153)

Remove the containers:

docker rm -f `docker ps -aq`

We can also run to ports we want with the -p option.

Wordpress Example

Wordpress is a common blogging applicaiton. It requires a database and webserver. Its written in php with MySQL and extremely popular! I use it for my blog [http://benincosa.com]

docker run -it -e MYSQL_ROOT_PASSWORD=cisco -p 3306:3306 -d --name wpsql mysql
docker run --name wordpress-test2 --link wpsql:mysql -p 80:80 -d  wordpress

We can also build another instance and run it on the same VM

docker run -it -e MYSQL_ROOT_PASSWORD=cisco -p 3307:3306 -d --name wpsql mysql
docker run --name wordpress-test2 --link wpsql:mysql -p 81:80 -d  wordpress

This one would now run on port 81. This makes us question design parameters. Do we get bigger VMs and load them with containers? Or lots of VMs and load them with smaller containers?

Building Containers

We'd like to build our own applications using containers. We do this with Dockerfiles. Let's create a directory with an image:

mkdir web
cd web

Now let's create a Dockerfie

# Contents of web/Dockerfile
FROM nginx
MAINTAINER Vallard Benincosa "vallard@benincosa.com"
COPY index.html /usr/share/nginx/html/

We need to create index.html

<!-- Contents of HTML -->
<html>
  <head>
    <title>Welcome to my container!</title>
  </head>
  <body style="background:#6070fe;color:#fff">
    <h1>Greetings from my container!</h1>
  </body>
</html>

Now we can build a container

docker build -t vallard/web .

Now we can run it

docker images
docker run -d -P vallard/web

Looking at the port from docker ps, you can figure out which one to connect to.

GitLab Example

This will be something more permament on the machine. So far all the container we've done are ephemeral. Let's show how to make these things last a little longer.

docker pull sameersbn/gitlab:latest
docker pull sameersbn/postgresql:latest
docker pull sameersbn/redis:latest

Create some directories to store data.

mkdir -p /opt/gitlab/data /opt/postgresql/data /opt/redis/data

Now let's start these containers

docker run --name=redis -d \
-v /opt/redis/data:/var/lib/redis \
sameersbn/redis:latest

docker run --name=postgresql -d \
-e 'DB_NAME=gitlabhq_production' \
-e 'DB_USER=gitlab' \
-e 'DB_PASS=f00bar123' \
-v /opt/postgresql/data:/var/lib/postgresql \
sameersbn/postgresql:latest

docker run --name=gitlab -d \
-e 'DB_TYPE=postgres' \
-e 'GITLAB_PORT=10080' \
-e 'GITLAB_SSH_PORT=10022' \
    -e 'GITLAB_HOST=172.20.200.20' \
-p 10022:22 \
-p 10080:80 \
-v /opt/gitlab/data:/home/git/data \
--link postgresql:postgresql \
--link redis:redisio \
sameersbn/gitlab:latest

Here we mapped port 80 to 10080 so we go to our server with (e.g: http://172.20.200.20:10080). It may take a while for this server to come up. (about 2 minutes). You can run the last gitlab container without the -d option to see it spawn up.

Root password is 5iveL!fe if this is the first time you launch it. If not, the database is persistent.

Architecturally we can mount this to the VM to save it off to be redundant.

Pretty cool!

Resources

The Dockerbook http://www.dockerbook.com

Docker's Website http://docker.org

Dockercon videos http://blog.docker.com/category/dockercon-2/

Some of my blogs http://benincosa.com/?tag=docker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment