This is a repository for a humble docker workshop.
The challenge of this repository is to build a dockerfile
and a docker-compose.yml
for a startup called HateCss,
Suppose that you're a frontend deleveloper in a startup called HateCss.
Your job, in the recently created enterprise, is to build its official website.
As a smart developer, you know that creating an website, in most part of the cases, requires the developer to install a bunch of dependencies and these dependencies might have some conflicts with other tools in your computer. To solve this issue (and many others) you have decided to execute this project inside a docker container.
To build a dockerfile you must at least have a basic knowledge about the project:
- The minimum necessary files to execute the code;
- The sequece of commands to build and/or run.
The HateCss website project runs using react and nodejs. If you're already familiar with the structure of a NodeJs project feel free to jump this section.
To build and run the website in your local machine you must have to installed nodejs.
Before running the project, a developer must have installed the necessary libraries to execute it. The installation can be perfomed with the following command:
npm install
In the end, you will notice that a folder called node_modules
will be created in the root of the project, which stores the dependent libraries and a file called package-lock.json
.
More information about package-lock.json.
To run the project you must execute:
npm start
├── node_modules/
├── package-lock.json
├── package.json
├── public/
├── README.md
└── src/
#The task
This will be a simple dockerfile.
As we have seem before, we know that to execute our project in our local machine we must execute the following commands:
Install node
npm install
npm start
Thus, we must build our dockerfile in a way that it performs these three operations. Can you do that?
The most basic commands to build a dockerfile are:
- FROM: uses a base image to build the dockerfile.
- WORKDIR: sets the working directory inside the container.
- RUN: It will executes this command to build the image. Which means that the image will contain the files generated by this command.
- CMD: It can only have one CMD instruction per dockerfile. The purpose of these instruction is to provide the default command when the container is executed. Thus, when you execute a container, this command will automatically take action.
- ADD: Copies new files from your computer and adds it to the image at a specified path.
- COPY: This instruction copies new files from your computer and adds it to the container at a specified path.
- ENV: set up the environment variables.
- etc...
The full list of commands can be checked in the official website.
You can also check this list of docker commands