This repository documents my journey learning Docker using the welcome-to-docker repository.
- Learn to use Docker through Visual Studio Code terminal
- Understand and analyze Dockerfile
- Create and manage Docker images and containers
- Make modifications and see them reflected
- Share Docker images through Docker Hub
- Docker Desktop installed
- Visual Studio Code
- Git
git clone https://github.com/docker/welcome-to-docker.git
cd welcome-to-docker
The Dockerfile contains important instructions:
- Uses Node.js 18 Alpine as base image
- Sets up the working directory
- Copies necessary files
- Installs dependencies
- Exposes port 3000
- Runs the application
docker build -t welcome-to-docker .
Here's what the build process looks like:
docker run -d -p 8088:3000 --name welcome-to-docker welcome-to-docker
docker ps
Visit http://localhost:8088
in your browser to see the initial page:
I modified the application to personalize it:
-
Located the source files:
- src/App.js
- src/App.css
-
Modified the background color and text, resulting in this yellow version:
To see the modifications, we need to:
# Rebuild the image
docker build -t welcome-to-docker .
# Remove existing container
docker rm -f welcome-to-docker
# Create new container
docker run -d -p 8088:3000 --name welcome-to-docker welcome-to-docker
docker login
Successful login confirmation:
# Tag the image
docker tag welcome-to-docker drux4r/welcome-to-docker
# Push to Docker Hub
docker push drux4r/welcome-to-docker
You can verify the pushed image in Docker Desktop:
# Pull the image
docker pull yanisb27/welcome-to-docker-yanis
# Run container
docker run -d -p 8089:3000 --name yanis-container yanisb27/welcome-to-docker-yanis
After modifying Yanis's image, here's the result with a red background:
# Access container shell
docker exec -it yanis-container sh
# List files
ls -R
# Exit container shell
exit
# Copy files locally
docker cp yanis-container:/app/src/App.css ./src/App.css
docker cp yanis-container:/app/src/App.js ./src/App.js
# Build new image
docker build -t derroce/webapp:dev .
# Tag with your username
docker tag derroce/webapp:dev drux4r/webapp:dev
# Push to Docker Hub
docker push drux4r/webapp:dev
docker build -t name .
- Build imagedocker run -d -p port:port --name container-name image-name
- Run containerdocker ps
- List running containersdocker rm -f container-name
- Remove containerdocker cp container:source destination
- Copy files from containerdocker tag source-image target-image
- Tag imagedocker push image-name
- Push to Docker Hub
- Original welcome-to-docker repository by Docker
- Inspired by Yanis's version (yanisb27)
- Modified and documented by drux4r