Skip to content

Using Docker in Builds

jeffreymzhou edited this page May 20, 2018 · 1 revision

Source: https://docs.travis-ci.com/user/docker/

How do you use Docker Images with Travis?

Travis CI builds allow you to both run and build Docker images, which is crucial for teams who need to test functions that require the redis server.

To use Docker, add the following lines to the .travis.yml file:

sudo: required

services:

  • docker

You can then run before_install steps to pull a Docker image, or build a docker image from a Dockerfile, which is what we did in lab 8.

docker build -t [label] . (if the Dockerfile is in the current directory)

What exactly is a Dockerfile?

Essentially, it is a text document that lists commands to assemble an image. These commands are the same commands that a user could type directly into the terminal/command line. Using a Dockerfile allows you to automate several command-line instructions in succession.

How to write a Dockerfile

Source: https://github.com/dockerfile/redis

Dockerfiles must adhere to a specific format and use a specific set of instructions. When you issue a docker build command, the current directory is the "build context" and the Dockerfile is assumed to be located here. (You may specify a location with file flag "-f"). The -t flag allows you to "tag" the image and name the new image, specifying where it is saved.

Use a .dockerignore file to exclude files irrelevant to the build. (Similar to .gitignore)

FROM:

The FROM instruction initializes a new build stage and sets the base image (image with no parent) up to take subsequent instructions. A valid Dockerfile must start with a FROM instruction.

RUN:

The RUN instruction will execute commands on top of the current image.

COPY:

The COPY instructions copies new files/directories from a given source and adds them into the filesystem in the given destination.

commands

docker build: builds an image from a given Dockerfile. You must specify the context by giving a PATH or URL.

Dockerfile best practices source: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/

How Docker works:

Source: https://nickjanetakis.com/blog/understanding-how-the-docker-daemon-and-docker-cli-work-together

Docker is a client <-> server application. (The daemon is the server, and CLI is one of many clients). CLI simply stands for Command Line Interface. When you download Docker, you get both the Docker daemon and CLI tools together.

Clone this wiki locally