Since, we went through most of the docker core concepts, Now lets see how to setup a simple webapp on docker
Step 1: Create a New Project
Create a new directory for your project and initialize it as a Git repository:
Step 2: Choose Your Framework
For this example, we’ll use Node.js and Express.js. You can choose any framework you like (e.g., Ruby on Rails, Python Flask) as long as it’s compatible with Docker.
Create a new file called app.js in the root directory:
Step 3: Create a Dockerfile
Create a new file called Dockerfile in the root directory:
This Dockerfile uses the official Node.js 14 image, sets the working directory to /app, copies the package.json file, installs dependencies, builds your application, exposes port 3000, and sets the command to start the application.
Step 4: Build Your Docker Image
Run the following command in your terminal:
This command tells Docker to build an image from the Dockerfile and tag it as my-web-app.
Step 5: Run Your Container
Start a new container using the following command:
This command tells Docker to start a new container from the my-web-app image, map port 3000 on your host machine to port 3000 in the container, and run the application.
Additional Resources