First View
Second View
Final View
Container
Docker VM

>docker version
C:\Users\manjunathk>docker version

How to inspect the container?
USING logs
C:\Users\manjunathk>docker create busybox echo hi manju
56645683d187fea45c81a56284d21acb95253c0d635dd297c2466bc9de97d299
C:\Users\manjunathk>docker start 56645683d187fea45c81a56284d21acb95253c0d635dd297c2466bc9de97d299
56645683d187fea45c81a56284d21acb95253c0d635dd297c2466bc9de97d299
C:\Users\manjunathk>docker logs 56645683d187fea45c81a56284d21acb95253c0d635dd297c2466bc9de97d299
hi manju
Executing commands in Running containers
Steps
1.docker run redis
2.docker exec -it container_id redis-cli


Command Prompt in Container
USING sh
C:\Users\manjunathk>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ff73636d1a18 redis "docker-entrypoint.s…" 24 minutes ago Up 24 minutes 6379/tcp charming_sanderson
4b0675b29df1 busybox "ping google.com" 56 minutes ago Up 56 minutes musing_euler
97afe1bf51ac jenkins "/bin/tini -- /usr/l…" 19 hours ago Up 19 hours 0.0.0.0:50000->50000/tcp, 0.0.0.0:9090->8080/tcp myjenkins100
C:\Users\manjunathk>docker exec -it ff73636d1a18 sh
# ls
# cd /
# ls
bin boot data dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
#
=================================================
Building Custom Images
Docker file:
Plain text file that is going to have couple of lines of configuration.placed inside of it.
Configuration to define how our container should behave

To Create and Image that runs redis-server
Steps
1. C:\Users\manjunathk>mkdir redis-image
2. Create a Dockerfile
3.Open/edit the Dockerfile and paste the below
#use an existing docker image as a base
FROM alpine
# Download and install a dependency
RUN apk add --update redis
#Tell the image what to when starts as a container
CMD ["redis-server"]
4.C:\Users\manjunathk\redis-image>docker build .
5. C:\Users\manjunathk\redis-image>docker run 9dd2aa65a843
See below
Why Apline?
Alpine Linux is a Linux distribution built around musl libc and BusyBox. The image is only 5 MB in size and has access to a package repository that is much more complete than other BusyBox based images. This makes Alpine Linux a great image base for utilities and even production applications.
apk - apache package
To rebuild my image above
#use an existing docker image as a base
FROM alpine
# Download and install a dependency
RUN apk add --update redis
RUN apk add --update gcc
#Tell the image what to when starts as a container
CMD ["redis-server"]
To tag and Image
docker build -t manjunathk/redis:latest .
manjunathk is my docker id
to run use below
docker run manjunathk/redis
Creation of Project:
sample Nodes S Page
create 2 files as below
mkdir simpleweb
package.json contains:
{
"dependencies": {
"express": "*"
},
"scripts": {
"start": "node index.js"
}
}
index.js contains
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send("Hi there");
});
app.listen(8080, () =>{
console.log('Listening on port 8080');
});
Just remember what we did for redis image
Now lets create Dockerfile.
# specify a image
# specify a image
FROM node:alpine
WORKDIR /usr/app
# install some dependencies
COPY ./package.json ./
RUN npm install
COPY ./ ./
# Default command
CMD ["npm", "start"]
To build an image go to the directory
docker build .
C:\Users\manjunathk\simpleweb>docker build .
To build a tag
C:\Users\manjunathk\simpleweb>docker build -t manjunathk/simpleweb .
1. docker build .
2. docker build -t manjunathk/simpleweb .
3. docker run -p 8080:8080 manjunathk/simpleweb
docker run -p 8080:8080 manjunathk/simpleweb
> @ start /
> node index.js
Listening on port 8080
run below in browser
192.168.99.100:8080
To Rebuild the Image when index.js is modified from Hi here to some random info
i.e
To do modify Dockerfile with
# specify a image
FROM node:alpine
WORKDIR /usr/app
# install some dependencies
COPY ./package.json ./
RUN npm install
COPY ./ ./
# Default command
CMD ["npm", "start"]
docker build -t manjunathk/simpleweb .
No comments:
Post a Comment