Dockerfile Flashcards

1
Q

Typical dockerfile

A
Dockerfile:  
FROM ubuntu:15.04  
COPY . /app  
RUN make /app  
CMD python /app/app.py 

RUN Will execute any commands in a new layer
CMD specifies what command to run within the container

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

ADD

COPY

A

ADD: Copies new files, directories or remote file URLs from and adds them to the filesystem of the image at the path .

COPY: Copies new files or directories from and adds them to the filesystem of the container at the path .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

WORKDIR

LABEL

A

Sets the working directory

LABEL: Adds metadata to an image

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Build the weather-app image

A

docker image build -t linuxacademy/weather-app:v1 .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

CMD

ENTRYPOINT

A

CMD: Provides a default for an executing container. There can only be one CMD instruction in a Dockerfile
ENTRYPOINT: Allows for configuring a container that will run as an executable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Set environment variable

ENV

A

ENV KEY Value

ENV PORT 3000

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Set environment variable
ENV

Redefine environment variable with –env flag

A

ENV KEY Value
Example of Dockerfile
ENV PORT 3000
EXPOSE $PORT

docker container run -d –name weather-dev -p 8082:3001 –env PORT=3001 linuxacademy/weather-app:v2
docker inspect wether-dev | grep ENV

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Build Arguments

ARG

A

Use the –build-arg flag when building an image:
–build-arg [NAME]=[VALUE]

Use the ARG instruction in the Dockerfile:
ARG [NAME]=[DEFAULT_VALUE]

cd docker_images
mkdir args
cd args
git clone https://github.com/linuxacademy/content-weather-app.git src
vi Dockerfile
# Create an image for the weather-app
FROM node
LABEL org.label-schema.version=v1.1
ARG SRC_DIR=/var/node
RUN mkdir -p $SRC_DIR
ADD src/ $SRC_DIR
WORKDIR $SRC_DIR
RUN npm install
EXPOSE 3000
CMD ./bin/www

docker image build -t linuxacademy/weather-app:v3 –build-arg SRC_DIR=/var/code .

docker image inspect linuxacademy/weather-app:v3 | grep WorkingDir

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Working with Non-privileged Users

A

cd ~/docker_images
mkdir node-non-privileged-user
cd node-non-privileged-user
git clone https://github.com/linuxacademy/content-weather-app.git src

vim Dockerfile
# Create an image for the weather-app
FROM node
LABEL org.label-schema.version=v1.1
RUN useradd -m -s /bin/bash node_user
USER node_user
ADD src/ /home/node_user
WORKDIR /home/node_user
RUN npm install
EXPOSE 3000
CMD ./bin/www

docker image build -t linuxacademy/weather-app-nonroot:v1 .

docker container run -d –name weather-app-nonroot -p 8086:3000 linuxacademy/weather-app-nonroot:v1
curl localhost:8086

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Connecting as a privileged user

A

docker container start test-build

docker container exec -u 0 -it test-build /bin/bash

How well did you know this?
1
Not at all
2
3
4
5
Perfectly