Docker Con 2020
Docker Con 2020
Getting Started With Docker
The story of never-ending installation & configuration and docker to the rescue
Why Docker?
-
Individual machines and operating systems need to be configured and upgraded. On top of that infrastructure, runs the application code
-
Machine configuration and upgrades are extremely error prone, servers were missed or misconfigured
Containers
Docker containers to the rescue
- A docker container composes of
base image + your application code
-
This composition creates your application docker image.
- When one of the images has a problem, you don’t have to shut down the entire server. Instead, you can fix the infrastructure or the application layer, build a new image, and deploy the image to that server, run it, ship it, and retire the buggy image.
Writing Dockerfile
FROM - tells docker to pull down the base image
WORKDIR - the directory where your application lives
ENV - the environment variables in your image
Building a docker container
$ docker build --help
$ docker build --tag <tag name> <path to the directory to build>
This builds an image called hello-world
using the current directory
Listing docker images
$ docker images
Running a docker container
A container is a process that’s isolated from the rest of the system. By default, your container is run in isolation:
- It has its own file system and its own network
- It’s restricted in CPU and memory usage
$ docker run --help
$ docker run <name of the image>
For a previously run image, you can use
$ docker start <container>
If you don’t map out a port, and connect it to any network, in the browser when you connect to it, you won’t be able to connect.
Diagnostics - to see if anything is running
List any running image
$ docker ps
List any image that was previously run, but has stopped
$ docker ps -a
Connect a port into your image
- Command is tricky and long, the community uses docker-compose
- many companies offer their own wrapper cli long around the docker cli
$ docker run -p 8080:80 --name hello -d hello-world
This command runs the image open to the world on port 8080, with the name hello, and it’s ran detached.
Now you’re connected to the world on port 8080. To further debug
$ docker logs <name of the container>
$ docker logs -f <name of the container>
-f
follows the logs locally
Publishing your image
- First, create a repo in docker Hub
- Then, tag and publish
$ docker tag <image> <username>/<repo name>
$ docker push <username>/<repo name>
Pulling and deploying
- Once the image is published, you can integrate your image into your CI/CD
- Then, it’s ready to deploy to AWS! Which is where your staging and production environments live.