export [email protected]
export LOCAL_HOST=localhost
export MongoDB_PASSWORD=butterzCUPz
export MongoDB_USERNAME=janeDOE
export WORDPRESS_DB_HOST=db
export WORDPRESS_DB_NAME=exampledb
export WORDPRESS_DB_PASSWORD=examplepass
export WORDPRESS_DB_USER=exampleuser
docker-compose up -d --build
docker-compose down
docker stack rm traefik
# docker info
sudo rm -rf devOps/
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519DO
git clone [email protected]:TurtleWolfe/devOps.git
cd devOps
docker stack deploy -c docker-compose.yml traefik
previous bash scriptGetting started with OpenSSHFail2BanUncomplicated FireWallescapeSED
jail.local.confadd Docker to previous Bash Script- git clone repo
Dockerfile
multi stagedev,prod, test, buildFrontEnd ReactTypeScript- NGINX
BackEnd express, Next, Nuxt or Nest TypeScript Backend- git clone repo
docker-compose UP
- Digital Ocean
60 day demo
40 days left on 60 day demo - Google Cloud PlatForm
free Forever server
Node lighter weight on Server than PHP - Amazon Web Service
lease $5 monthly
- DevLama
Social NetWork API & React playlist - Traversy Media
API Master Class - David Herron
By the end of this Node.js book, you’ll have gained practical Node.js web development knowledge and be able to build and deploy your own apps on a public web hosting solution. - Academind
placeholder
- YouTube, Udemy & Packt
-
MoshOne
-
Nav Auth
-
Academind Git Hub
-
code splitting
-
.DSP XD imports
# update apt-get libraries
sudo apt-get update
# install required packages
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
# get the GPG key for docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo apt-key add -
# validating the docker GPG key is installed
sudo apt-key fingerprint 0EBFCD88
# adding the docker repository
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
# update apt-get libraries again
sudo apt-get update
# install docker
sudo apt-get install docker-ce
# validate install with version command
docker --version
# validating functionality by running a container
sudo docker run hello-world
# add the current user to the docker group
sudo usermod -aG docker $USER
# validate that sudo is no longer needed
docker run hello-world
# install docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
39 docker system info
40 docker system info | grep Swarm
41 docker swarm init
42 docker system info | grep Swarm
43 docker swarm --help
44 docker swarm ca --help
45 docker swarm ca
46 docker swarm join-token
47 docker swarm join-token --help
48 docker swarm join-token -q
49 docker swarm join-token manager
50 docker swarm join-token worker
51 docker swarm unlock-key
52 docker swarm init
56 docker service create --help
64 docker container ls -a
65 docker container rm -f $(docker container ls -aq)
66 docker container ls -a
67 docker container run --detach --name web-server003 --publish 80:80 nginx
68 docker container ls -a
70 docker container logs --follow --timestamps web-server003
72 docker container top web-server003
74 docker container inspect web-server003
76 sudo apt install jq
77 docker container inspect --format '{{json .State}}' web-server003 | jq
## 78
79 docker container stats
81 docker container stats
82 docker network ls
83 docker network prune
84 docker network ls
85 docker network prune
86 docker network ls
87 docker network inspect specifics-over --format '{{json .IPAM.Config}}' | jq
88 docker network inspect bridge --format '{{json .IPAM.Config}}' | jq
89 docker version
90 docker search --limit 5 alpine
91 docker search --help
98 docker
99 docker info
100 docker search --limit 5 alpine
101 docker network inspect bridge --format '{{json .IPAM.Config}}' | jq
102 docker network ls
103 docker container stats
104 docker container inspect --format '{{json .State}}' web-server003 | jq
105 docker container top web-server003
106 docker container run --detach --name web-server003 --publish 80:80 nginx
107 docker info
108 docker container ls -a
109 docker container nginx start
110 docker container start nginx
111 docker container ls -a
112 docker container start 2abfac
113 history
114 clear
115 docker system info
116 docker system info | grep Swarm
117 docker swarm ca
118 docker container inspect --format '{{json .State}}' web-server003 | jq
119 clear
120 docker container stats
121 docker network inspect specifics-over --format '{{json .IPAM.Config}}' | jq
122 docker network inspect bridge --format '{{json .IPAM.Config}}' | jq
123 docker container stats
124 docker network inspect specifics-over --format '{{json .IPAM.Config}}' | jq
125 docker container stats
126 docker system info | grep Swarm
127 docker container start 2abfac
128 docker container ls -a
129 docker info
130 docker container top web-server003
131 docker search --limit 5 alpine
132 docker info
133 docker
134 docker container ls -a
135 docker images ls -a
136 docker images
137 docker version
138 docker info
139 docker container run --detach --name web-server003 --publish 80:80 nginx
140 docker container ls
141 docker images ls -a
142 docker container ls -a
143 docker network inspect web-server003 --format '{{json .IPAM.Config}}' | jq
144 docker container inspect --format '{{json .State}}' web-server003 | jq
145 docker container top web-server003
146 docker container ls
147 docker container ps
148 docker container ps -a
149 docker ps
150 docker container exec -it web-server0003 bash
151 docker container exec -it web-server003 bash
152 ls
153 docker container exec -it web-server003 bash
154 history
155 code .
156 sudo snap install code
157 sudo snap install code --classic
158 sudo apt update
159 docker container exec -it web-server0003 bash
160 docker container exec -it web-server003 bash
161 docker container run --detach --name web-server003 --publish 80:80 nginx
162 ocker container run --detach --name web-server003 --publish 80:80 -v $(pwd):/usr/share/nginx/html nginx
163 docker container run --detach --name web-server003 --publish 80:80 -v $(pwd):/usr/share/nginx/html nginx
164 ls
165 cd /
166 ls
167 cd /usr/share/
168 ls
169 cd
170 ls
171 cd /usr/share/
172 ls
173 cds ..
174 ls
175 cd
176 ls
177 docker container run --detach --name web-server003 --publish 80:80 -v $(pwd):/usr/share/nginx/html nginx
178 git status
179 docker container run --detach --name web-server003 --publish 80:80 -v $(pwd):/usr/share/nginx/html nginx
180 docker image build -t btrav/nginx-website .
181 docker images
182 docker container ls
183 docker container run --detach --name web-server003 --publish 80:80 -v $(pwd):/usr/share/nginx/html nginx
192 sudo rm -r ChatSocketIO -f
193 ls
194 git clone [email protected]:TurtleWolf/ChatSocketIO.git
195 git clone https://github.com/TurtleWolf/ChatSocketIO.git
203 docker container run --detach --name web-server003 --publish 80:80 -v $(pwd):/usr/share/nginx/html nginx
204 docker container start 2abfac
205 exit
206 docker container run --detach --name web-server003 --publish 80:80 -v $(pwd):/usr/share/nginx/html nginx
207 docker container run --restart=always -d -i -t 2abfac /bin/bash
208 docker container
209 docker container ls
210 docker container run --detach --name web-server003 --publish 80:80 -v $(pwd):/usr/share/nginx/html nginx
211 docker container rm -f $(docker container ls -aq)
212 docker container ls
213 docker images ls
214 docker image ls
215 docker container run --restart=always -d -i -t nginx /bin/bash
216 docker image ls
217 docker container ls
218 docker container rm -f $(docker container ls -aq)
219 docker container run --detach --name web-server003 --restart=always --publish 80:80 -v $(pwd):/usr/share/nginx/html nginx
220 docker container ls
221 docker container rm -f $(docker container ls -aq)
222 sudo docker container run --detach --name web-server003 --restart=always --publish 80:80 -v $(pwd):/usr/share/nginx/html nginx
223 docker container rm -f $(docker container ls -aq)
224 ls
225 docker container run --restart=always -d -i -t ubuntu /bin/bash
226 docker container ls
227 docker container rm -f $(docker container ls -aq)
228 docker container run --restart=always -d -i -t nginx /bin/bash
229 docker container rm -f $(docker container ls -aq)
230 docker container run --restart=always -d -i -t --publish 80:80 nginx /bin/bash
231 docker container ls
232 docker container rm -f $(docker container ls -aq)
233 docker container ls
234 docker container run --detach --name web-server003 --publish 80:80 nginx
235 docker container run --detach --name web-server003 --publish 80:80 --restart=always nginx
236 docker container rm -f $(docker container ls -aq)
237 docker container run --detach --name web-server003 --publish 80:80 --restart=always nginx
238 docker container ls
239 docker container info
240 docker container stats
241 docker container ls
242 docker container ls -a
243 docker container ls info
244 docker container inspect --format '{{json .State}}' web-server003 | jq
245 docker network inspect web-server003 --format '{{json .IPAM.Config}}' | jq
246 sudo apt update
247 sudo apt upgrade
248 sudo reboot
249 docker container ls info
250 docker network inspect web-server003 --format '{{json .IPAM.Config}}' | jq
251 docker container inspect --format '{{json .State}}' web-server003 | jq
252 docker container run --help
253 docker container --restart string
254 docker container --restart help
255 docker container run --help
256 docker container ls
257 docker container inspect web-server003
258 docker container inspect \ --format='{{.NetworkSettings.IPAddress}}' $ID172.17.0.2
259 docker container ls
260 docker container inspect \ --format='{{.NetworkSettings.IPAddress}}' $IDweb-server003
261 docker container inspect --help
262 docker container inspect web-server003
263 docker container inspect web-server003 | grep RestartPolicy
264 docker container inspect web-server003 | grep "RestartPolicy": {
265 docker container inspect web-server003 | grep RestartPolicy
266 docker container inspect --help
267 docker container inspect web-server003 -f RestartPolicy
268 docker container inspect web-server003
269 docker container inspect web-server003 "RestartPolicy": {
270 docker container inspect web-server003 RestartPolicy
271 docker container inspect web-server003
272 docker image ls
273 docker container ls
274 docker container inspect web-server003 | jq "."
275 docker container inspect --format '{{json. .Config.Labels))' web-server003 | jq "."
276 docker container inspect --format '{{json. .Config.Labels))' web-server003 | jq "."
277 docker container inspect --format `{{json. .Config.Labels))` web-server003 | jq "."
278 docker container inspect --format '{{json. .Config.Labels))' web-server003 | jq "."
279 docker container inspect --format '{{json. .Config.Labels))' web-server003 | jq
280 docker info
281 docker images
282 docker-machine
docker container exec -it web-server0003 bash
docker container run --detach --name web-server003 --publish 80:80 --restart=always nginx
# cd usr/share/nginx/html
docker container start 2abfac
docker container run --restart=always -d -i -t 2abfac /bin/bash
# docker remove all
docker container run --detach --name web-server003 --publish 80:80 -v $(pwd):/usr/share/nginx/html nginx
# docker REACT
docker container run --detach --name web-server003 --publish 80:80 -v $(pwd):/usr/share/nginx/html react
# docker DRUPAL
docker container run --detach --name web-server003 --publish 80:80 -v $(pwd):/usr/share/nginx/html drupal
# docker WORD PRESS
docker container run --detach --name web-server003 --publish 80:80 -v $(pwd):/usr/share/nginx/html wordpress
# docker DRAGGABLE DICE
docker container run --detach --name web-server003 --publish 80:80 -v $(pwd):/usr/share/nginx/html draggable dice
# docker Free Code Camp Template
docker container run --detach --name web-server003 --publish 80:80 -v $(pwd):/usr/share/nginx/html freecodecampTEMPLATE
# ChatSocketIO.git
git clone https://github.com/TurtleWolf/ChatSocketIO.git
# docker-node-mongo
git clone https://github.com/TurtleWolf/docker-node-mongo
# dockerLAMP
git clone [email protected]:TurtleWolf/dockerLAMP.git
# Show commands & management commands
docker
# Docker version info
docker version
# Show info like number of containers, etc
docker info
# Create & run a container in foreground
docker container run -it -p 80:80 nginx
# Create an run a container in background
docker container run -d -p 80:80 nginx
# Shorthand
docker container run -d -p 80:80 nginx
# Naming Containers
docker container run -d -p 80:80 --name nginx-server nginx
- Looked for image called nginx in image cache
- If not found in cache, it looks to the default image repo on Dockerhub
- Pulled it down (latest version), stored in the image cache
- Started it in a new container
- We specified to take port 80- on the host and forward to port 80 on the container
- We could do "$ docker container run --publish 8000:80 --detach nginx" to use port 8000
- We can specify versions like "nginx:1.09"
# List running containers
docker container ls
OR
# List running containers
docker ps
# List all containers (Even if not running)
docker container ls -a
# Stop container
docker container stop [ID]
# Stop all running containers
docker stop $(docker ps -aq)
# Remove container (Can not remove running containers, must stop first)
docker container rm [ID]
# To remove a running container use force(-f)
docker container rm -f [ID]
# Remove multiple containers
docker container rm [ID] [ID] [ID]
# Remove all containers
docker rm $(docker ps -aq)
# Get logs (Use name or ID)
docker container logs [NAME]
# List processes running in container
docker container top [NAME]
Docker containers are often compared to virtual machines but they are actually just processes running on your host os. In Windows/Mac, Docker runs in a mini-VM so to see the processes youll need to connect directly to that. On Linux however you can run "ps aux" and see the processes directly
# List the images we have pulled
docker image ls
# We can also just pull down images
docker pull [IMAGE]
# Remove image
docker image rm [IMAGE]
# Remove all images
docker rmi $(docker images -a -q)
- Images are app bianaries and dependencies with meta data about the image data and how to run the image
- Images are no a complete OS. No kernel, kernel modules (drivers)
- Host provides the kernel, big difference between VM
# Some sample container creation
# NGINX:
docker container run -d -p 80:80 --name nginx nginx (-p 80:80 is optional as it runs on 80 by default)
# APACHE:
docker container run -d -p 8080:80 --name apache httpd
# MONGODB:
docker container run -d -p 27017:27017 --name mongo mongo
# MYSQL:
docker container run -d -p 3306:3306 --name mysql --env MYSQL_ROOT_PASSWORD=123456 mysql
# CONTAINER INFO
# View info on container
docker container inspect [NAME]
# Specific property (--format)
docker container inspect --format '{{ .NetworkSettings.IPAddress }}' [NAME]
# Performance stats (cpu, mem, network, disk, etc)
docker container stats [NAME]
# Create new nginx container and bash into
docker container run -it --name [NAME] nginx bash
- i = interactive Keep STDIN open if not attached
- t = tty - Open prompt
winpty docker container run -it --name [NAME] nginx bash
# Run/Create Ubuntu container
docker container run -it --name ubuntu ubuntu
# You can also make it so when you exit the container does not stay by using the -rm flag
docker container run --rm -it --name [NAME] ubuntu
# Access an already created container, start with -ai
docker container start -ai ubuntu
# Use exec to edit config, etc
docker container exec -it mysql bash
# Alpine is a very small Linux distro good for docker
docker container run -it alpine sh
(use sh because it does not include bash) (alpine uses apk for its package manager - can install bash if you want)
# Get port
docker container port [NAME]
# List networks
docker network ls
# Inspect network
docker network inspect [NETWORK_NAME]
("bridge" is default)
# Create network
docker network create [NETWORK_NAME]
# Create container on network
docker container run -d --name [NAME] --network [NETWORK_NAME] nginx
# Connect existing container to network
docker network connect [NETWORK_NAME] [CONTAINER_NAME]
# Disconnect container from network
docker network disconnect [NETWORK_NAME] [CONTAINER_NAME]
# Detach network from container
docker network disconnect
# tags are labels that point ot an image ID
docker image ls
Youll see that each image has a tag
# Retag existing image
docker image tag nginx btraversy/nginx
# Upload to dockerhub
docker image push bradtraversy/nginx
# If denied, do
docker login
# Add tag to new image
docker image tag bradtraversy/nginx bradtraversy/nginx:testing
-
FROM - The os used. Common is alpine, debian, ubuntu
-
COPY # Copies files from host to container
-
ADD # Copies files from host to container
-
ENV - Environment variables
-
ARG - Environment variables
-
CMD - Final command run when you launch a new container from image
-
ENTRYPOINT - Final command run when you launch a new container from image
-
RUN - Run commands/shell scripts, etc
-
EXPOSE - Ports to expose
-
WORKDIR - Sets working directory (also could use 'RUN cd /some/path')
# From the same directory as Dockerfile
docker image build -t [REPONAME] .
- If you re-run the build, it will be quick because everythging is cached.
- If you change one line and re-run, that line and everything after will not be cached
- Keep things that change the most toward the bottom of the Dockerfile
# Custom Dockerfile for html paqge with nginx
FROM nginx:latest # Extends nginx so everything included in that image is included here
WORKDIR /usr/share/nginx/html
COPY index.html index.html
# Build image from Dockerfile
docker image build -t nginx-website
# Running it
docker container run -p 80:80 --rm nginx-website
# Tag and push to Dockerhub
docker image tag nginx-website:latest btraversy/nginx-website:latest
docker image push bradtraversy/nginx-website
# Check volumes
docker volume ls
# Cleanup unused volumes
docker volume prune
# Pull down mysql image to test
docker pull mysql
# Inspect and see volume
docker image inspect mysql
# Run container
docker container run -d --name mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=True mysql
# Inspect and see volume in container
docker container inspect mysql
- You will also see the volume under mounts
- Container gets its own uniqe location on the host to store that data
- Source: xxx is where it lives on the host
# Check volumes
docker volume ls
There is no way to tell volumes apart for instance with 2 mysql containers, so we used named volumes
# Named volumes (Add -v command)(the name here is mysql-db which could be anything)
docker container run -d --name mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=True -v mysql-db:/var/lib/mysql mysql
# Inspect new named volume
docker volume inspect mysql-db
- Can not use in Dockerfile, specified at run time (uses -v as well)
- ... run -v /Users/brad/stuff:/path/container (mac/linux)
- ... run -v //c/Users/brad/stuff:/path/container (windows)
TIP: Instead of typing out local path, for working directory use $(pwd):/path/container - On windows may not work unless you are in your users folder
# Run and be able to edit index.html file (local dir should have the Dockerfile and the index.html)
docker container run -p 80:80 -v $(pwd):/usr/share/nginx/html nginx
docker container run --detach --name web-server003 --publish 80:80 -v $(pwd):/usr/share/nginx/html nginx
# Go into the container and check
docker container exec -it nginx bash
cd /usr/share/nginx/html
ls -al
# You could create a file in the container and it will exist on the host as well
touch test.txt
- Configure relationships between containers
- Save our docker container run settings in easy to read file
- 2 Parts: YAML File (docker.compose.yml) + CLI tool (docker-compose)
- containers
- networks
- volumes
version: '2'
# same as
# docker run -p 80:4000 -v $(pwd):/site bretfisher/jekyll-serve
services:
jekyll:
image: bretfisher/jekyll-serve
volumes:
- .:/site
ports:
- '80:4000'
# To run
docker-compose up
# You can run in background with
docker-compose up -d
# To cleanup
docker-compose down
# Drupal with PostgreSQL
#
# Access via "http://localhost:8080"
# (or "http://$(docker-machine ip):8080" if using docker-machine)
#
# During initial Drupal setup,
# Database type: PostgreSQL
# Database name: postgres
# Database username: postgres
# Database password: example
# ADVANCED OPTIONS; Database host: postgres
version: '3.1'
services:
drupal:
image: drupal:8-apache-alpine
ports:
- 8080:80
volumes:
- /var/www/html/modules
- /var/www/html/profiles
- /var/www/html/themes
# this takes advantage of the feature in Docker that a new anonymous
# volume (which is what we're creating here) will be initialized with the
# existing content of the image at the same location
- /var/www/html/sites
restart: always
postgres:
image: postgres:10
environment:
POSTGRES_PASSWORD: example
restart: always
README.md package-lock.js Dockerfile DockerIgnore DockerCompose.yml DockerCompose-Production.yml
1727 sudo apt purge nodejs
1729 sudo apt remove nodejs
1741 sudo npm uninstall -g create-react-app
1739 sudo apt install nodejs
sudo npm install -g [email protected]
- docker-compose Alpine dependencies (8)
- pip install docker-compose
- 2 spaces, no tabs in YAML
- : (key:value pairs)
-
- (lists)
WORKDIR
, notcd
ormkdir
(unless... ?)docker-compose up -d --build
to force rebuilddocker-compose down -v
to delete volumes
build
stop
ps
push
logs
exec
COPY
overADD
npm cache clean --force
CMD node
not npmWORKDIR
coverscd
&mkdir
unless you needchown
thenRUN mkdir
ENV
node versionStretch
more current thanJessie
USER node
beforeCMD
to enable non-root user- each
RUN
creates a new layer
USER node
RUN mkdir app && chown -R node:node .
COPY --chown=node:node . .
docker-compse exec -u root
- each line is a new layer
EXPOSE
higher in ordering because it changes less oftenCOPY package.json package-lock.json* ./
RUN npm
install &&npm
cache clean --forceCOPY . .
RUN apt-get
once and early
- COPY, if doing more than one file the .
/
is required &&
must run bothdocker build -t assignment1 .
- docker build
--no-cache
-t assignment1 . docker run -p 80:3000 assignment1
- FROM
node
asprod
- ENV
NODE_ENV
=production
- FROM
prod
asdev
- ENV
NODE_ENV
=development
- FROM
dev
astest
- ENV
NODE_ENV
=development
ENV
configuration- log
stdout/stderr
- .dockerignore
- pin all versions
- Graceful exit
SIGTERM/INIT
- 12 factor
- left side of
bind mount
should always just be a dot - don't bind mount databases
- don't copy in local code
DDforWin
drive permissionsPerms:
Linus != Windows:delegated
docker-bg-sync
docker-compose run
docker-compose exec
docker-compose run api
npm idocker-compose exec api
strapi --helpdocker-compose exec api
bash
nginx-proxy
enviroment:-VIRTUAL_HOST
=traefik-proxy
labels:traefic.frontend.rule=Host:nginx.localhost