Skip to content

Commit

Permalink
docker
Browse files Browse the repository at this point in the history
  • Loading branch information
lerndevopss committed May 10, 2022
1 parent 6858955 commit d268685
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docker/scenarios/1.install-docker-on-ubuntu-linux.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Install Docker `Using Script`

```
sudo wget https://raw.githubusercontent.com/lerndevops/labs/master/scripts/installDocker.sh -P /tmp
sudo chmod 755 /tmp/installDocker.sh
sudo bash /tmp/installDocker.sh
```


# Install Docker With `Manual Steps`

```
sudo su -
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
## Test the installation by running a simple container:
docker run hello-world
## FYI Only ## Check Available Version for Install
apt-cache madison docker-ce | awk '{print $3}'
```
47 changes: 47 additions & 0 deletions docker/scenarios/2.how-to-run-containers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
### there are many docker images available on [DockerHub](https://hub.docker.com), we can just pull them & start running containers

# Get Images from `DockerHub`
```
docker pull tomcat:latest -- to pull a docker image from docker hub
docker image ls -- to display the images on your local machine
docker inspect tomcat:latest -- to view the detaied information in JSON output
docker image rm tomcat:latest -- to remove a image from local machine
docker image prune -a -- to remove all unused images from local machine
```

# how to run containers from a docker image

### two ways we can run the images

## run a container in `foreground mode`
```
docker run tomcat:latest
Note:
-- the terminal will be stuck after running above commnd
-- use Ctrl + C to come out
```
## run a container in `detached mode`
```
docker run -d nginx:latest
Note:
-- always creates new container & detaches from the terminal you are working on ( goes in background process ))
```

## how to see running/stopped containers
```
docker ps -- to see all running containers
docker ps -a -- to see all running and exited/stopped containers
```

## container LifeCycle
```
docker stop <container id> -- to stop a container
docker start <container id> -- to start a stopped container
docker restart <container id> -- to restart a container
docker rm <container id> -- to remove a stopped/exited container
docker rm -f <container id> -- to remove a container forcefully though it is in running state
docker inspect <container id> -- to view detailed information about the continaer in JSON format
```
27 changes: 27 additions & 0 deletions docker/scenarios/3.how-to-login-to-container.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## how to login/get inside a running container

### Create a Container
```
docker run -d tomcat:latest -- creates a new container in detached mode
docker ps -- displays the running containers, note the container id
```

### login to container
```
docker exec -it <container id> /bin/bash
Ex:
root@vm1:~# docker exec -it fda4e3ccd59d /bin/bash
root@fda4e3ccd59d:/usr/local/tomcat#
```

### Logout of Container
```
use "exit" to come out of container
Ex:
root@fda4e3ccd59d:/usr/local/tomcat# exit
exit
root@vm1:~#
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## how to access the applications running inside the container `from external world (browser)`

> **services running inside a container can never be accessed direcltry, we always need to publish/expose them on to docker host while we create the containers**
> **we need to publish/expose the services using `-P (capital)` OR `-p (small)` with in the docker run command**
## use `-P ( capital )`

### Create a Container & Publish
```
docker run -d -P nginx
-- docker will publish/expose the port number dynamically on docker host & maps with port running inside the cont
docker ps
-- to check the container port
```
### Access Application
```
to access:
-- in the browser http://<docker-host-IP>:<exposed port>
-- ex: http://52.14.62.88:32768
```

## use `-p ( small )`

### Create a Container & Publish
```
docker run -d -p 9090:80 nginx
-- docker will publish/expose the port numbr as defined on docker host & maps with port running inside the cont
docker ps
-- to check the container port
```
### Access Application
```
to access:
-- in the browser http://<docker-host-IP>:<exposed port>
-- ex: http://52.14.62.88:9090
```
14 changes: 14 additions & 0 deletions docker/scenarios/install-docker-compose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Install DockerCompose

### Install Using Script
```
sudo wget https://raw.githubusercontent.com/lerndevops/labs/master/scripts/installDockerCompose.sh -P /tmp
sudo chmod 755 /tmp/installDockerCompose.sh
sudo bash /tmp/installDockerCompose.sh
```

### Manual Installation Steps
```
sudo curl -L https://github.com/docker/compose/releases/download/$DC_VERSION/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
```
30 changes: 30 additions & 0 deletions docker/scenarios/install-docker-on-other-linux-os.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Install Docker on CentOS/Fedora/amznLinux

### Install Docker `Using Script`

```
sudo wget https://raw.githubusercontent.com/lerndevops/labs/master/scripts/installDocker.sh -P /tmp
sudo chmod 755 /tmp/installDocker.sh
sudo bash /tmp/installDocker.sh
```


### Install Docker With `Manual Steps`

```
sudo yum install -y device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker
## Test the installation by running a simple container:
docker run hello-world
```

# Add your user to the docker group
```
## Add your user to the docker group, giving the user permission to run docker commands:
sudo usermod -aG docker devops
```

0 comments on commit d268685

Please sign in to comment.