...

/

Dockerfile Creation and Explanation

Dockerfile Creation and Explanation

Learn how to create a Dockerfile.

Dockerfile for Rails app

A Dockerfile is made up of various instructions such as FROM, RUN, COPY, and WORKDIR, each capitalized by convention. Let’s look at a specific example.

Here is a basic Dockerfile for running our Rails app.

FROM ruby:2.7 
RUN apt-get update -yqq 
RUN apt-get install -yqq --no-install-recommends nodejs 
COPY myapp /usr/src/app/ 
WORKDIR /usr/src/app 
RUN bundle install 

Every image has to start from another, preexisting image. For that reason, every Dockerfile begins with a FROM instruction, which specifies the image to be used as its starting point. Typically, we will look for a starting image that is close to what we need but more general. That way we can extend and customize it to our needs.

Dockerfile explanation

FROM instruction

The first line of our Dockerfile is:

FROM ruby:2.7.2 

This is saying that our image will be based on the ...