# Dockerfile - Build your own Docker Image

### What is Dockerfile?

A Dockerfile is a script that automatically creates containers on the Docker platform. A Dockerfile is basically a text document that contains all the commands a user could call on the command line to assemble an image.

![](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2FBa1mNY4ixyna8Zi3aJct%2Fimage.png?alt=media\&token=35e368f5-a568-483f-a7ad-823d15b0cb1f)

![Dockerfile commands](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2FKVmnFROeOF8K5D1nuZW5%2Fimage.png?alt=media\&token=000e4828-f652-4c2c-8828-a614f89d12b9)

Each instruction in a Dockerfile results in an Image Layer:&#x20;

![](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2FGKsQLMmniI9kUdXoX4CL%2Fimage.png?alt=media\&token=46d4fd31-9085-472b-8627-610e5f7bc6d7)

It's common to start with an existing base image in your application's Dockerfile:

![](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2F8g8TRK7MtpR9ktQHVwIs%2Fimage.png?alt=media\&token=0000d94f-f6a2-46f5-a2e0-f26028c32db8)

Command to build an image from a Dockerfile and a context&#x20;

![Uses the current directory ( . ) as build context ](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2FlQoWpCqYVqWiiLyLuaMw%2Fimage.png?alt=media\&token=9b81dc97-d80c-467a-9931-55be3672a4f8)

The build's context is the set of files at a specified location&#x20;

{% code title="Example of Dockerfile" %}

```
FROM python:3.8

# set a directory for the app
WORKDIR /usr/src/app

# copy all the files to the container
COPY . .

# install dependencies
RUN pip install --no-cache-dir -r requirements.txt

# define the port number the container should expose
EXPOSE 5000

# run the command
CMD ["python", "./app.py"] 
```

{% endcode %}

![i](https://2601183865-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8QpIzz6VwCOTMwaqKYa3%2Fuploads%2F8jnwGvjfFjeDktTinW8z%2Fimage.png?alt=media\&token=5b03152b-2b7d-4ee0-ad6b-09d32055e8f3)
