Table of contents
๐ Task:
๐ Create a Dockerfile for a simple web application (e.g. a Node.js or Python app)
๐ถ First, you'll need to create a Dockerfile. This file contains instructions for building a Docker image. You can use the vi
text editor to create a file named Dockerfile
(no file extension) and define the instructions within it. Here's an example Dockerfile for a basic web application:
๐ Build the image using the Dockerfile and run the container.
๐ถ Open a terminal or command prompt, navigate to the directory containing your Dockerfile, and run the following command to build the Docker image.
docker build. -t <name of image>
๐ถ Run the Docker Container: After building the Docker image, you can run a container from it using the following command.
docker run -d -p 5000:5000 <your_image_name>:<your_image_tag>
--name
specifies the name you want to give to the container.-p
maps port 5000 inside the container to port 5000 on your host machine. You can change the port mapping as needed.
๐ Verify that the application is working as expected by accessing it in a web browser
๐ถ Once the container is running, you can access the application in a web browser by entering http://localhost
or the IP address of your host machine, depending on your Docker setup and the application's configuration.
๐ Push the image to a public or private repository (e.g. Docker Hub )
๐ถ Log In to Docker Hub: If you haven't already, log in to your Docker Hub account using the docker login
command:
๐ถ Tag your Docker image with your Docker Hub username, the repository name, and the tag you want (e.g., latest
):
๐ถ Replace your-image-name
with your image's name, your-docker-hub-username
with your Docker Hub username, and your-repository-name
with the desired repository name on Docker Hub.
๐ถ Push the tagged image to Docker Hub. This will upload your image to your public Docker Hub repository.
docker push your-docker-hub-username/your-repository-name:latest
๐ถ Visit the Docker Hub website and log in to your account to verify that your image has been successfully pushed and is accessible to the public.