DEV Community

technonotes-hacker
technonotes-hacker

Posted on

Kubernetes - Day - 07 - Questions Docker ( 1 to 6 )

1 . Install Docker on your local machine. Verify the installation by running the hello-world container.


  docker pull hello-world
  docker run hello-world
  docker ps -a
  docker logs 030152e160a9
Enter fullscreen mode Exit fullscreen mode

2. 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.


docker pull nginx
docker run -d -p 8080:80 --name nginx_test nginx
Enter fullscreen mode Exit fullscreen mode

3. 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');
});

--> what is docker file ? - A Docker-file is a plain text file that contains a step-by-step set of instructions used to build a Docker image.
-- > It acts as the blueprint or recipe for your application.

  • Alpine is the OS (Operating System). It acts as the very thin, lightweight floorboards at the bottom of the container.

  • Node.js Engine sits on top of Alpine to read and execute your JavaScript files.

  • NPM (Node Package Manager) is the tool built into Node.js that goes out to the internet to download extra libraries (like express).


    docker build -t my-node-app .
    docker ps
    docker ps -a
    docker run -d -p 3000:3000 --name my-node-app my-node-app
    docker ps -a
    docker ps
Enter fullscreen mode Exit fullscreen mode

4. Tag the Docker image my-node-app from Task 3 with a version tag v1.0.0.


docker tag my-node-app my-node-app:v1.0.0
Enter fullscreen mode Exit fullscreen mode

5. Push the tagged image from Task 4 to your Docker Hub repository.


    docker login
    docker login -u sathishpy1808
    docker tag my-node-app my-node-app:v1.0.0
    docker images
    docker tag my-node-app:v1.0.0 sathishpy1808/my-node-app:v1.0.0
    docker push sathishpy1808/my-node-app:v1.0.0
Enter fullscreen mode Exit fullscreen mode

6. Run a container from the ubuntu image and start an interactive shell session inside it. You can run commands like ls, pwd, etc.


docker pull ubuntu
docker run -it ubuntu bash
Enter fullscreen mode Exit fullscreen mode

Notes

  • docker ps -a --> shows all containers which are also stopped
  • docker ps --> only running containers.

Top comments (0)