Showing posts with label DOCKER. Show all posts
Showing posts with label DOCKER. Show all posts

Friday, June 24, 2022

Tomcat , J2EE Web app inside Container : DOCKER

 Deploying Your First Web App to Tomcat on Docker (softwareyoga.com)

softwareyoga/docker-tomcat-tutorial: A basic tutorial on running a web app on Tomcat using Docker (github.com)

Deploying Your First Web App to Tomcat on Docker | Cprime

https://hub.docker.com/_/tomcat


#FROM tomcat:8.0-alpine
#FROM tomcat:jre8-openjdk FROM tomcat:9.0.8-jre8-alpine ADD target/*.war /usr/local/tomcat/webapps/ EXPOSE 8080 CMD ["catalina.sh", "run"]


docker run -p 8080:8080 -it --rm --name oms-monolith oms
docker image ls 
docker container ls -a

RUN vs CMD vs ENTRYPOINT : DOCKER

https://awstip.com/docker-run-vs-cmd-vs-entrypoint-78ca2e5472bd


The three Dockerfile instructions RUN , CMD and ENTRYPOINT look similar and can easily cause confusions. Let’s discuss their differences in this article.

RUN vs CMD vs ENTRYPOINT

  • RUN executes commands and creates new image layers.
  • CMD sets the command and its parameters to be executed by default after the container is started. However CMD can be replaced by docker run command line parameters.
  • ENTRYPOINT configures the command to run when the container starts, similar to CMD from a functionality perspective.

Shell Format vs Exec Format

We can specify the command to be run by RUN, CMD and ENTRYPOINT in two ways: Shell format and Exec format, which have subtle differences in usage.

Shell Format

Shell format has the following form:

<instruction> <command>

For example:

RUN apt-get install python3CMD echo "Hello world"ENTRYPOINT echo "Hello world"

When the command is executed, the bottom layer of the shell format will call /bin/sh -c <command>. When you run commands in Shell format, the environment variable that defined in ENV command will be inherited.

ENV name Cloud ManENTRYPOINT echo "Hello, $name"# Output
Hello, Cloud Man

Exec Format

Exec format has the following form:

<instruction> ["executable", "param1", "param2", ...]

For example:

RUN ["apt-get", "install", "python3"]CMD ["/bin/echo", "Hello world"]ENTRYPOINT ["/bin/echo", "Hello world"]

When the command is executed, <command> will be called directly and will not be parsed by the shell. The environment variable that defined in ENV will not be passed as well.

ENV name Cloud ManENTRYPOINT ["/bin/echo", "Hello, $name"]# Output
Hello, $name

The Exec format is recommended for CMD and ENTRYPOINT because the instructions are more readable and easier to understand. RUN then both formats are fine.

RUN

The RUN command is typically used to install applications and software packages.

RUN executes the command on top of the current image, and by creating a new image layer. Dockerfile often contains multiple RUN instructions.

CMD

The CMD directive allows user to specify the default command executed by the container. This command runs when the container starts and no other command is specified for docker run .

  1. If docker run specifies another command, the default command specified by CMD will be ignored.
  2. If there are multiple CMD instructions in the Dockerfile, only the last CMD is valid.

CMD has three formats:

  1. Exec format: CMD [“executable”,”param1",”param2"]
  2. CMD [“param1”, ”param2"], this format is used in combination of ENTRYPOINT , to provide extra parameters
  3. Shell format: CMD command param1 param2

Exec format is recommended as it provides better readbility.

ENTRYPOINT

The ENTRYPOINT directive allows the container to run as an application or service.

ENTRYPOINT looks similar to CMD in that both specify the command to execute and its parameters. The difference is that ENTRYPOINT will not be ignored and will be executed, even if other commands are specified when running docker run.

ENTRYPOINT has two formats:

  1. Exec format: ENTRYPOINT [“executable”, “param1”, “param2”] This is the recommended format for ENTRYPOINT.
  2. Shell format: ENTRYPOINT command param1 param2

The parameters in ENTRYPOINT are always used, while the extra parameters of CMD can be dynamically replaced when the container starts. For example:

ENTRYPOINT ["/bin/echo", "Hello"]CMD ["world"]# Output
Hello world

Note the shell format of ENTRYPOINT ignores any arguments provided by CMD or docker run.

FROM busyboxENTRYPOINT echo helloCMD world# Output
hello

Conclusion

  1. Use the RUN command to install applications and packages, and build images.
  2. If the purpose of the Docker image is to run an application or service, such as running a MySQL, the ENTRYPOINT command in the Exec format should be used in preference. CMD can provide additional default parameters for ENTRYPOINT, and the default parameters can be replaced by the docker run command line.
  3. If you want to set the default startup command for the container, you can use the CMD command. Users can override this default command in the docker run command line.

Monday, August 9, 2021

kubectl : How to copy files from within Docker kubectl into PC/Laptop

//Inside Container
kubectl exec -it -n fda mongodb-2 /bin/bash
cd tmp
mkdir -p 10Aug2021
mongoexport --db fda-platform-extraction --collection cleanup_metadata --out    /tmp/10Aug2021/cleanup_metadata_DEV.json 

//Inside JumpServer
mkdir -p 10Aug2021
cd 10Aug2021
kubectl cp mongodb-2:/tmp/10Aug2021/  .  -n fda

Sunday, July 18, 2021

Docker: Docker Commands : Exhaustive

docker image pull <image>
docker image ls

docker container run <image> 
docker container run <image> --name  <containerName>
docker container run <image> -d
docker container run <image> -p HostPort:ContainerPort
docker container run -it <image> command

docker container 

docker container start <container>
docker container start -at <container>

docker container exec -it  <container>  command

docker container top

Would the following two commands create a port conflict error with each other?
NO ? Why ?
Each of below lines creates own containers

docker container run -p 80:80 -d nginx
docker container run -p 8080:80 -d nginx





Tuesday, July 13, 2021

Docker Compose

  • docker-compose logs --follow elasticsearch
  • docker-compose -f docker-compose.elastic.yml up -d
  • docker-compose ps 
  • docker-compose down 
  • docker-compose up 
  • docker-compose -f filename up
  • docker-compose images
  • docker-compose down -v                                                [Removes all volumes created by docker]

Commands:
  build              Build or rebuild services
  bundle             Generate a Docker bundle from the Compose file
  config             Validate and view the Compose file
  create             Create services
  down               Stop and remove containers, networks, images, and volumes
  events             Receive real time events from containers
  exec               Execute a command in a running container
  help               Get help on a command
  images             List images
  kill               Kill containers
  logs               View output from containers
  pause              Pause services
  port               Print the public port for a port binding
  ps                 List containers
  pull               Pull service images
  push               Push service images
  restart            Restart services
  rm                 Remove stopped containers
  run                Run a one-off command
  scale              Set number of containers for a service
  start              Start services
  stop               Stop services
  top                Display the running processes
  unpause            Unpause services
  up                 Create and start containers
  version            Show the Docker-Compose version information


Friday, July 9, 2021

Docker Desktop + WSL2 + Ubuntu + WSL +docker

 docker run -it --rm --privileged --pid=host justincormack/nsenter1

\\wsl2$ - Special Shared Path on Windows - which hides complex Path of Windows 
Docker Desktop + Ubuntu(WSL2) --- linked
Docker commands run from both
but Images go in Docker Desktop only -  \\wsl$\docker-desktop-data\version-pack-data\community\docker
Volume should be uploaded from Ubuntu/WSL2
Volume upload from Windows wont work
You can upload Folders from Windows to \\wsl$ shared path -specfically here  - \\wsl$\Ubuntu-20.04\home\karankaw
and it will show up as ~ in WSL2/Ubuntu

Thursday, July 8, 2021

Azure - Pipeline - Add Approver for Stage

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass