Install Docker on your local machine. Verify the installation by running the hello-world container.
Pull the nginx image from Docker Hub and run it as a container. Map port 80 of the container to port 8080 of your host.
Create a Dockerfile for a simple Node.js application that serves βHello Worldβ on port 3000. Build the Docker image with tag my-node-app and run a container. Below is the sample index.js file.
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello World');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
4. Tag the Docker image my-node-app from Task 3 with a version tag v1.0.0.
5. Push the tagged image from Task 4 to your Docker Hub repository.
6. Run a container from the ubuntu image and start an interactive shell session inside it. You can run commands like ls, pwd, etc.
7. Create a Dockerfile for a Go application that uses multi-stage builds to reduce the final image size. The application should print βHello Dockerβ. Sample Go code.
package main
import "fmt"
func main() {
fmt.Println("Hello Docker")
}
8. Create a Docker volume and use it to persist data for a MySQL container. Verify that the data persists even after the container is removed. Try creating a test db.
9. Create a custom Docker network and run two containers (e.g., nginx and mysql) on that network. Verify that they can communicate with each other.
10. Create a docker-compose.yml file to define and run a multi-container Docker application with nginx as a web server and mysql as a database.
11. Scale the nginx service in the previous Docker Compose setup to run 3 instances.
12. Create a bind mount to share data between your host system and a Docker container running nginx. Modify a file on your host and see the changes reflected in the container.
13. Add a health check to a Docker container running a simple Node.js application. The health check should verify that the application is running and accessible.
Sample Healthcheck API in node.js,
const express = require('express');
const app = express();
// A simple route to return the status of the application
app.get('/health', (req, res) => {
res.status(200).send('OK');
});
// Example main route
app.get('/', (req, res) => {
res.send('Hello, Docker!');
});
// Start the server on port 3000
const port = 3000;
app.listen(port, () => {
console.log(`App is running on http://localhost:${port}`);
});
14. Modify a Dockerfile to take advantage of Dockerβs build cache, ensuring that layers that donβt change are reused.
15. Run a PostgreSQL database in a Docker container and connect to it using a database client from your host.
16. Create a custom Docker network and run a Node.js application and a MongoDB container on the same network. The Node.js application should connect to MongoDB using the container name.