FROM golang:1.10.3 as builder
WORKDIR /go/src/app
COPY . .
ADD . /go/src/goproject/
# install dependency
RUN go get -d -v ./...
# build go app
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
# CMD ["app"] # if not step2
# Setp 2 move to scratch
FROM alpine:latest
COPY --from=builder /go/src/app/app /
CMD ["/app"]
EXPOSE 80
สั่ง Build ด้วย Command
$ CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
จะได้ app เอาไป run ใน linux
สร้าง Dockerfile สำหรับ เอาไป run ใน Linux
FROM scratch
ADD app /
CMD ["/app"]
EXPOSE 80
สั่ง build dockerfile
docker build -t <ชื่อ Image> .
docker run --name <ชื่อ Container> -p <port ข้างนอก>:<Port ใน image> -d <ชื่อ Image>
ตัวอย่าง
docker run --name <ชื่อ Container> -d -p 80:80
- Postgresql Backup Command
- Postgresql Restore Command
- Move Database Script
- Install PostgreSQL Docker Replication
- PostgreSQL Docker Backup
pg_dump --host <ip> --port <port> --username "postgres" --format custom --blobs --verbose --file "<backuptofilename>" <databasename>
OR Linux
pg_dump -Fc <databasename> > outputfilename
pg_restore.exe --host <ip> --port <port> --username "postgres" --dbname <database_name> --verbose <backupfile>
OR Linux
pg_restore --dbname <database_name> --verbose <backupfile>
select t1.datname AS db_name,
pg_size_pretty(pg_database_size(t1.datname)) as db_size
from pg_database t1
order by pg_database_size(t1.datname) desc;
SELECT
relname as "Table",
pg_size_pretty(pg_total_relation_size(relid)) As "Size",
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as "External Size"
FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC;
pg_dump -C -h 192.168.2.98 -U postgres toc | psql -h localhost -U postgres toc
version: '3'
services:
postgresql-master:
image: docker.smldatacenter.com:5443/postgresql:10.4-replication
container_name: postgresql_master
restart: always
environment:
- POSTGRES_PASSWORD=<password>
volumes:
- ./master_data:/var/lib/postgresql/data
ports:
- 5432:5432
postgresql-slave1:
image: docker.smldatacenter.com:5443/postgresql:10.4-replication
restart: always
environment:
- POSTGRES_MASTER_SERVICE_HOST=postgresql_master
- REPLICATION_ROLE=slave
volumes:
- ./slave1_data:/var/lib/postgresql/data
ports:
- 54321:5432
version: '3'
services:
postgresql-backup:
image: smlsoft/smlpgbackup:10.4
restart: always
volumes:
- ./backups:/var/lib/postgresql/backups
environment:
- BACKUPHOUR=22
- BACKUPMINUTE=45
- PGHOST=sml_postgresql
Option
Env | Description |
---|---|
BACKUPHOUR | เวลาที่จะทำการสำรองข้อมูล (0-23) |
BACKUPMINUTE | ระบุนาที |
PGHOST | ชื่อ Server เก็บข้อมูล (postgresql) |
PGPORT | Port |
PGUSER | รหัสผู้ใช้ |
PGPASS | รหัสผ่าน |
<slaveserver>dev.smlsoft.com</slaveserver><slaveport>54329</slaveport><slaveuser>postgres</slaveuser><slavepassword>sml</slavepassword>
qnapsmldev.myqnapcloud.com