Getting Started With Docker
Getting Started With Docker
C O NT E NT S
221
Getting Started
With Docker
About Docker
Docker Architecture
Getting Started
Typical Local Workflow
Other Helpful Commands
By Christopher M. Judd
A B O U T D O CK E R
Almost overnight, Docker has become the de facto
standard that developers and system administrators
use for packaging, deploying, and running distributed
applications. It provides tools for simplifying
DevOps by enabling developers to create templates
called images that can be used to create lightweight
virtual machines called containers, which include
their applications and all of their applications
dependencies. These lightweight virtual machines
can be promoted through testing and production
environments where sysadmins deploy and run them.
Docker
Images
Docker
Like a tiny virtual machine that is created from
Container the instructions found within the Docker image
originated
Docker
Client
Docker
Host
G E T T I N G S TA R T E D W I T H D O C K E R
Docker Hub.
Docker is an open-source solution that runs natively
on Linux but also works on Windows and Mac using a
lightweight Linux distribution and VirtualBox. Many
Site24x7
DOCKER MONITORING
D O CK ER A RCHITEC TU R E
Docker utilizes a client-server architecture and a remote
API to manage and create Docker containers built upon
Linux containers. Docker containers are created from
CPU
D Z O NE, INC.
Cache
Memory
DZ O NE .C O M
I/O
Site24x7
Cache
Memory
I/O
CPU
DOCKER MONITORING
Analyze resource usage and performance
metrics of containers and hosts
LEARN MORE
Application
Server
Cloud
Network
Website Performance
Website Availability
Public Status Pages
Mail Server
DNS
Java
.NET
RUM
Ruby on Rails
Mobile APM
Windows
Linux
On-Premise
SQL
Amazon EC2
Amazon RDS
Amazon S3
VMware
Docker
Router
Firewall
Switch
www.Site24x7.com
3
Docker
Registry
Docker
Machine
build the container from the Docker Hub, then build and
run it.
To run the simple hello-world container to make sure
commands:
docker run hello-world
G E T TI N G STA RTE D
INSTALLING DOCKER
the message.
T YPI C A L LO C A L WO R K FLOW
HOT
TIP
curl -L https://github.com/docker/machine/releases/
download/v0.4.0/docker-machine_linux-amd64 > /
usr/local/bin/docker-machine
chmod +x /usr/local/bin/docker-machine
an image with your team or the world, you can push your
RUNNING A CONTAINER
D Z O NE, INC .
DZ O NE .C O M
REPOSITORY
<none>
mysql
you find an image you want, such as mysql, execute the pull
command to download the image.
docker pull mysql
TAG
<none>
5.5.45
IMAGE ID
4b9b8b27fb42
0da0b10c6fd8
VIRTUAL SIZE
214.4 MB
213.5 MB
Docker Hub and cache the image locally. If you dont want
the current image and instead want a specific version, you
clearer.
HOT
TIP
REPOSITORY
est-mysql
mysql
TAG
latest
5.5.45
IMAGE ID
4b9b8b27fb42
0da0b10c6fd8
VIRTUAL SIZE
214.4 MB
213.5 MB
If you cant find what you need or dont trust the source of
configurations.
RUNNING AN IMAGE
FROM mysql:5.5.45
RUN echo America/New_York | tee /etc/timezone &&
dpkg-reconfigure --frontend noninteractive tzdata
docker build .
command:
docker ps
docker images
name they were created from, the command that was run,
D Z O NE, INC .
DZ O NE .C O M
any ports that software are listening on, and the name of
the container.
CONTAINER ID IMAGE
COMMAND
30645f307114 est-mysql /entrypoint.sh mysql
PORTS NAMES
3306/tcp serene_brahmagupta
TAGGING AN IMAGE
Now that you have an image that you have run and
Finally, you are ready to push your image to Docker Hub for
the world to use or your team to use via a private repository.
First, if you havent done so already, you will need to go
listening to port 3306, but that does not mean you are able
docker login
into your Docker Hub account, you will see the new repository.
docker-machine ip default
D Z O NE, INC .
DZ O NE .C O M
EXECUTE COMMANDS
OTH E R H E LPFU L CO M M A N DS
LIST CONTAINERS
You have already seen how the ps command can list the
docker ps -a
to start or remove.
it is secure.
docker exec -it my-est-mysql bash
REMOVE CONTAINERS
When you are done using a container, rather than having it
RUN CONTAINER
docker rm my-est-mysql
REMOVE IMAGES
list all the locally cached images. These images can take
D O CK E R FI LE
command:
HOT
TIP
LIST PORTS
Its often helpful to know what ports are exposed by
a container, such as port 3306 for accessing a MySQL
INSTRUCTIONS
LIST PROCESSES
If you need to see the processes running in a container, you
INSTRUCTION
DESCRIPTION
can use the top command (similar to running the Linux top
FROM
MAINTAINER
command):
docker top my-est-mysql
D Z O NE, INC .
DZ O NE .C O M
7
INSTRUCTION
DESCRIPTION
RUN
ENTRYPOINT
CMD
LABEL
ENV
COPY
ADD
Alternative to copy
WORKDIR
EXPOSE
VOLUME
USER
DOCKERFILE EXAMPLE
EXPOSE 3306
CMD [mysqld]
blob/5836bc9af9deb67b68c32bebad09a0f7513da36e/5.5/
Dockerfile, which uses many of the available instructions.
FROM debian:jessie
RUN groupadd -r mysql && useradd -r -g mysql
mysql
RUN mkdir /docker-entrypoint-initdb.d
RUN apt-get update && apt-get install -y perl
--no-install-recommends && rm -rf /var/lib/apt/
lists/*
RUN apt-get update && apt-get install -y libaio1
&& rm -rf /var/lib/apt/lists/*
RUN gpg --keyserver ha.pool.
sks-keyservers.net --recv-keys
A4A9406876FCBD3C456770C88C718D3B5072E1F5
D Z O NE, INC .
DZ O NE .C O M
D O CK E R M ACH I N E
docker-machine ls
start command.
docker-machine start qa
docker-machine env qa
eval $(docker-machine env qa)
HOT
TIP
LIST MACHINES
If you need to see what machines you have configured you
can run the docker-machine ls command:
CREDITS:
Editor: G. Ryan Spain | Designer: Yassee Mohebbi | Production: Chris Smith | Sponsor Relations: Chris Brumfield | Marketing: Chelsea Bosworth
JOIN NOW
DZone communities deliver over 6 million pages each month to more than 3.3 million software
developers, architects and decision makers. DZone offers something for everyone, including
news, tutorials, cheat sheets, research guides, feature articles, source code and more.
Copyright 2015 DZone, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any
DZONE,
DZONE, INC.
INC.
form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.
DZONE, INC.
150 PRESTON EXECUTIVE DR.
CARY, NC 27513
888.678.0399
919.678.0300
REFCARDZ FEEDBACK WELCOME
[email protected]
SPONSORSHIP OPPORTUNITIES
DZONE.COM
DZONE.COM
[email protected]
VERSION 1.0
$7.95