docker

Kubernetes

Kubernetes on Digital Ocean with Ingress

  • Create Kubernetes with Create-Button
  • Install One-click app Ingress
  • Make sure DNS is routed to the ip address of the kubernetes-stack
  • Add pods, create from form and choose INTERNAL service.
  • When removing pod double check you have removed all the services and routes etc etc.

Add Ingres yaml

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: web
  namespace: default
spec:
  rules:
  - host: nginx01-test.webaddress.com
    http:
      paths:
      - backend:
          serviceName: nginx01
          servicePort: 80
  - host: nginx02-test.yourwebaddress.com
    http:
      paths:
      - backend:
          serviceName: nginx02
          servicePort: 80

Minikube

Minikube

run an Angular app in local kubernetes Minikube env with image from Docker.io

create angular app
in angular.ts custom output path: ... "options": { "outputPath": "dist/pw", ...

create nginx file:

events{}
http {
    include /etc/nginx/mime.types;
    server {
        listen 80;
        server_name localhost;
        root /usr/share/nginx/html;
        index index.html;
        location / {
            try_files $uri $uri/ /index.html;
        }
    }
}

create Dockerfile

Dockerfile

FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
COPY ./dist/pw /usr/share/nginx/html 

Minikube

On mac: install via brew minikube and hyperkit.
brew install hyperkit
brew install minikube
brew install kubectl

minikube start --vm-driver=hyperkit

in other terminal window

minikube dashboard

back to the first window:
(after a ng build --prod)

docker build -t DOCKER_ACCOUNTNAME/pw-app:latest .

docker push docker.io/DOCKER_ACCOUNTNAME/pw-app:latest

kubectl create deployment pw-app --image=docker.io/DOCKER_ACCOUNTNAME/pw-app:latest

kubectl expose deployment pw-app --type=NodePort --port=80
minikube service pw-app

GCloud

Dotnet core 2.2 project

In Program.cs

public static void Main(string[] args)
{
    CreateWebHostBuilder(args).UseUrls("http://:8080/").Build().Run();
}
Dockerfile
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
ENV ASPNETCORE_URLS=http://
:${PORT}
WORKDIR /app
COPY --from=build-env /app/out .

ENTRYPOINT ["dotnet", "tuinhok.dll"]

.dockerignore

bin\
obj\

docker build and push

docker build -t gcr.io/<gcp-project>/<appName>:latest .
docker push gcr.io/<gcp-project>/<appName>:latest

Node express server

const express = require('express')
const app = express()
const port = process.env.PORT || 8080

app.get('/', (req, res) => {
  res.json({
    message: 'Hello World'
  })
})

app.listen(port, () => console.log(`Example app listening on port ${port}!`))

dockerfile for a node project:

FROM node:10

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
COPY package*.json ./
RUN npm install

COPY . .
CMD ["node", "server-app.js"]

MSSQL server with Docker

https://database.guide/how-to-install-sql-server-on-a-mac/

get docker container

sudo docker pull microsoft/mssql-server-linux:latest

create docker container
password needs
Uppercase letters, Lowercase letters, Base 10 digits, and Symbols..
docker run -e'ACCEPT_EULA=Y' -e'MSSQL_SA_PASSWORD=YourPassword123!' -p 1433:1433 --name sqlserver -d microsoft/mssql-server-linux

start docker container
docker exec -it sqlserver bash

run as SA
/opt/mssql-tools/bin/sqlcmd -U SA

view password (!)
echo $MSSQL_SA_PASSWORD

change password:
docker exec -it sqlserver2 /opt/mssql-tools/bin/sqlcmd -U SA'Root123!' -Q'ALTER LOGIN SA WITH PASSWORD="YourPassword123!"'

download
mssql datastudio

create and save data in volume

docker run -e'ACCEPT_EULA=Y' -e'MSSQL_SA_PASSWORD=YourPassword123!' -p 1433:1433 --name sqlserver2 -v sqlservervolume:/var/opt/mssql -d microsoft/mssql-server-linux

to see volumes
docker volume ls

backup external to local desktop...
docker cp newsqlserver:/var/opt/mssql ~/Desktop

copy into container
docker cp ~/Desktop/filetocopy.ext newsqlserver:/

backup from within the mssql in new backup folder
/opt/mssql-tools/bin/sqlcmd -U SA //get in db
1> BACKUP DATABASE Products TO DISK ='/var/opt/mssql/backup/Products.bak'
2> GO

exit
copy it to desired location...

code first approach:
dotnet ef migrations add InitialMigration
dotnet ef database update

sql operations studio:
no longer in active development...

azure datastudio:
same as sql operations studio...
https://docs.microsoft.com/en-us/sql/azure-data-studio/download?view=sql...

in azure datastudio:
new query

IF NOT EXISTS (
   SELECT name
   FROM sys.databases
   WHERE name = N'TutorialDB'
)
CREATE DATABASE [TutorialDB]
GO

ALTER DATABASE [TutorialDB] SET QUERY_STORE=ON
GO

Docker.qcow2 never shrinks

~/Library/Containers/com.docker.docker/

rm Docker.qcow2

Tags: 

Docker

cleanup

~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2
never shrinks...

Dockerfile recipes

Java hello

FROM openjdk:14-alpine
COPY out/artifacts/testdockerhello_jar/testdockerhello.jar /usr/src/hello.jar
CMD java -cp /usr/src/hello.jar Main

Spring basic

with maven pom.

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <finalName>docker-spring-demo</finalName>
    </build>

Dockerfile
FROM openjdk:11

EXPOSE 8080

ADD target/docker-spring-demo.jar app.jar

ENTRYPOINT ["java","-jar", "app.jar"]

Mysql recipe

docker run --name mysql -e MYSQL_USER=user -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=databasename -p 3306:3306 -d mysql/mysql-server

Sails

run sails from local dir in docker conatiner
docker container run -it -p 1337:1337 -v $(pwd):/server artificial/docker-sails /bin/bash

Swift

run docker app
then

docker pull swift
docker pull postgres:alpine

docker container run -d -p 3306:3306 --name mysql -e MYSQL_RANDOM_ROOT_PASSWORD=yes  mysql
docker container run --name mysql -p 3306:3306 -e MYSQL_RANDOM_ROOT_PASSWORD=yes -d mysql
docker container logs mysql
docker exec -it mysql bash -l

docker container run -d --name mysql -e MYSQL_ROOT_PASSWORD=root -p 3306 -v /Users/lappie2010/Documents/docker/mysql/:/var/lib/mysql mysql


docker container logs mysql

docker container run -d --name webserver -p 8080:80 httpd

docker container run -d --name proxy -p 80:80 nginx


docker run --cap-add sys_ptrace -it --privileged=true swift bash

Docker Mysql + Wordpress

docker container run -d \
    --name wordpress \
--link mysql:mysql\
    -p 8080:80 \
    -e WORDPRESS_DB_PASSWORD=root \
    wordpress

    docker container run -d \
        --name mysql \
        -e MYSQL_ROOT_PASSWORD=root \
        -e MYSQL_DATABASE=wordpress \
        mysql

Subscribe to RSS - docker