Skip to content
Snippets Groups Projects
Commit 0779d38e authored by Adam Lewenberg's avatar Adam Lewenberg
Browse files

more work on lesson2

parent ba9e375f
No related branches found
No related tags found
No related merge requests found
# Dockerfile
FROM debian:buster-slim
LABEL maintainer="adamhl@stanford.edu"
ADD run.sh /root/run.sh
RUN chmod a+x /root/run.sh
CMD /root/run.sh
# Lesson 2: Introduction to Docker builds
1. Why are containers useful? What are their advantages over a
traditional server?
- containers are light
- containers are portable
- containers are isolated
- containers can be run "immutably"
- containers are built hierarchically
- developers can create applications without a full server-stack
1. What are some limitations of containers?
- interaction is more difficult for multiple containers than for
multiple server process (although Kubernetes helps)
- some overhead so not quite as fast as "bare-metal" processes
- there are several decades worth of server administration best practices
and tools but only a few years for containers
- not good for large tightly-integrated applications (e.g., Oracle database)
1. Question: what is the difference between an "image" and a "container"?
(See also [this Stackoverflow
question](https://stackoverflow.com/questions/23735149/what-is-the-difference-between-a-docker-image-and-a-container).
1. Most Docker images are build on top of existing "base" images. These
base containers are usually hosted in Docker Hub. For example, all Debian
releases come as Docker images; see https://hub.docker.com/_/debian for a
list of the base Debian Docker images.
1. Let's build a "Hello, world." Docker image. We will build it on a
Debian buster base. First, pull the Docker image:
$ docker pull debian:buster-slim
# We pull the "slim" image to save disk space
1. Here is an application that echos "Hello, world." and then exits. Save
this in the file `run.sh`:
#!/bin/sh
echo "Hello, world."
exit 0
1. Now we create a "Dockerfile" that tells the build process how to create
the image. We use `debian:buster-slim` as the base and "add" the command
`run.sh`. The first argument of `ADD` is the *local* copy of the file and
the second argument is where we want the file to put in the image.
# Dockerfile
FROM debian:buster-slim
LABEL maintainer="adamhl@stanford.edu"
ADD run.sh /root/run.sh
1. We want to make sure that the script will run, so make it executable.
# Dockerfile
FROM debian:buster-slim
LABEL maintainer="adamhl@stanford.edu"
ADD run.sh /root/run.sh
RUN chmod a+x /root/run.sh
1. Docker containers must be told which command to run. We do this with
the `CMD` directive
# Dockerfile
FROM debian:buster-slim
LABEL maintainer="adamhl@stanford.edu"
ADD run.sh /root/run.sh
RUN chmod a+x /root/run.sh
CMD /root/run.sh
1. We are now ready to build the image:
$ docker build . -t hello-world
$ docker images | grep hello-world
1. Note that the tag is `latest` (the default).
#!/bin/sh
echo "Hello, world."
exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment