Skip to content

Commit

Permalink
ISSUE-90 add entrypoint/command introduction and lecture titles
Browse files Browse the repository at this point in the history
  • Loading branch information
ivorscott committed Nov 15, 2021
1 parent dbbe985 commit 84936ae
Showing 1 changed file with 74 additions and 17 deletions.
91 changes: 74 additions & 17 deletions dockerfiles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,78 @@ Table of Contents

## Understanding ENTRYPOINT and CMD

- What
- Entrypoints are ...
- Commands are ...
- Why
- Both are often used together (they compliment each other).
- How
### What's an ENTRYPOINT? What's a CMD?

#### ENTRYPOINT

An `ENTRYPOINT` allows you to configure a container that will run as an executable.

There are _two_ forms: the _exec form_ and the _shell form_.

__SYNTAX__

```Dockerfile
ENTRYPOINT ["executable", "param1", "param2"] # execform
```

```Dockerfile
ENTRYPOINT command param1 param2 # shellform
```

When you run a container, any command line arguments will be appended to the entrypoint.

This feature allows us to create images with a default executable in mind or change the default entrypoint of a base image.

For example, the default entrypoint for the offical nginx image is `ENTRYPOINT ["/docker-entrypoint.sh"]` [1](https://github.com/nginxinc/docker-nginx/blob/2decc81a019b5df087c9162d3621b1c9beb3104f/mainline/debian/Dockerfile). We can override this to print the contents of the container filesystem instead.

```Dockerfile
FROM nginx:1.21.4
ENTRYPOINT ["ls"]
```
#### CMD

`CMD` provides defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case the executable is the entrypoint.

There are _three_ forms:

__SYNTAX__

```Dockerfile
CMD ["executable","param1","param2"] # execform
```

```Dockerfile
CMD ["param1","param2"] # parameter-only form
```

```Dockerfile
CMD command param1 param2 # shellform
```

__NOTE:__ If you omit the executable, you must have an ENTRYPOINT defined in the Dockerfile.

Using the same custom nginx image, this is how it would look like using CMD.

```dockerfile
FROM nginx:1.21.4
CMD ["ls"]
```
Now you might be wondering, if we can use CMD in the same way as ENTRYPOINT why does Docker need both? The truth is, they compliment each other. ENTRYPOINT and CMD are often used together. When a command is present, it's appended to the end of the entrypoint.

For example:

```dockerfile
FROM nginx:1.21.4
ENTRYPOINT ["ls"]
CMD ["-l"]
# becomes "ls -l"
```

__SYNTAX__
```Dockerfile
ENTRYPOINT ./main
CMD ["--my-flag", "1" ] # --my-flag 1
```
#### Summary

Both ENTRYPOINT and CMD provide increased flexibility in how we write Dockerfiles. They allow us to provide good defaults in our images, with the option to change this behavior at runtime.

### Lecture 1: Something interesting
### Lecture 1: ENTRYPOINT

In this lecture, we will discuss ENTRYPOINT.

Expand All @@ -35,7 +92,7 @@ Resources

- https://docs.docker.com/engine/reference/builder/#entrypoint

### Lecture 2: Something else
### Lecture 2: CMD

In this lecture, we will discuss CMD.

Expand All @@ -51,7 +108,7 @@ Resources

- https://docs.docker.com/engine/reference/builder/#cmd

### Lecture 3: One more thing
### Lecture 3: OVERRIDING ENTRYPOINT and CMD in the CLI

In this lecture, we will discuss command line properties.

Expand All @@ -74,7 +131,7 @@ Resources
- https://docs.docker.com/engine/reference/commandline/run/#options (--entrypoint)


### Lecture 4: One more thing
### Lecture 4: Using ENTRYPOINT and CMD in Docker Compose

In this lecture, we will discuss compose properties.

Expand Down Expand Up @@ -127,7 +184,7 @@ Resources

D)

3. Select the correct way to day X?
3. Select the correct way to do X?

A)

Expand Down Expand Up @@ -156,4 +213,4 @@ For this assignment, your task is to...

Assignment Files

[/dockerfiles/entrypoint-command-assignment-1](/dockerfiles/entrypoint-command-assignment-1)
[/dockerfiles/entrypoint-command-assignment-1](/dockerfiles/entrypoint-cmd-assignment-1)

0 comments on commit 84936ae

Please sign in to comment.