Wednesday, 21 September 2022
Monday, 19 September 2022
MySQL 5.7 default DateTime
MySQL 5.7 default dateTime mode, zero dateTime is not allowed.
Since 0000-00-00 00:00:00
is not a valid DATETIME
value, your database is broken. That is why MySQL 5.7 – which comes with NO_ZERO_DATE
mode enabled by default – outputs an error when you try to perform a write operation.
So a solution to solve this error by reset the mode, i.e.
SET SQL_MODE='ALLOW_INVALID_DATES';
Friday, 16 September 2022
Docker
Docker Concepts
Docker
In an English dictionary, a docker is a person employed in a port to load and unload ships. Docker refers to a product and a vendor that provides software to run containerized applications.
Container
Containers are isolated from each other, and it is also isolated from the underlying OS. It is a self-contained system and can be run on any OS.
Image
Image may be considered as a blueprint, a piece of instructions to build a container. Docker uses the image as a blueprint to create containers and running them on top of the host OS.
Docker Volume
Docker containers are supposed to be ephemeral, created and destroyed by automation tools at any time so that they cannot persist data. To persist data from a container, we have to use a docker volume to plug a host file folder into a container. If a docker is not mounted a volume explicitly, a container will automatically create a volume inside the host. Otherwise, it allows mounting an explicit volume on a container.
docker volume ls: to show all volumes
there are three types of volumes, a default volume, a mounted specific host folder, or a named volume. In production, a named volume is often applied.
Docker File
A DockerFile is a text document that contains all the commands that a user could call on the command line to assemble an image. Using the docker build, users can create an automated build that executes several command-line instructions in succession.
commands in DockerFile
FROM: define the base image, on which we will be building
ADD: add files to the container being built. Add<source><destination in container>
RUN: add layers to the base image, by installing component
CMD: is used to run commands at the start of the container. these commands run only when there is no argument specified while running the container.
ENTRYPOINT: os is used strictly to run commands the moment the container initializes. The difference between CMD and ENTRYPOINT will run irrespective of whether the argument is specified.
ENV: define environment variables in the container runtime.
run apt-get update
run apt-get -y install apache2
Docker Commands
docker pull <image>: Pull an image or a repository from a registry
docker ps: show all running containers
docker ps -a: show all containers, including running and exited ones
docker run -it -d <image>: run a docker container from a image, returning a <container-id>
-it: give me an interactive terminal
-d: run the container as a daemon
docker run -it <container > : leaving user an active console that showing app logs and input
docker run <container > : console input is deactivated; user cannot interact with the console
docker exec <container-id>: get the terminal of the running container.
docker exec -it container-id bash
-it: give me an interactive terminal
bash: is a Linux terminal to interact with
step out of a container, typing 'exit';
docker start <container>: Start one or more stopped containers
docker stop <container>: Stop one or more running containers
docker container rm <containername|containerId>: Removing one or more exited containers
docker container rename <containername> <newname>: renaming a container
docker kill <container-id>: stoping the container in a forced way.
docker rm <container-id>: removing the container from the docker supervision.
docker rmi <image-id>: removing a specific image.
docker rmi $(docker images) : removing all docker images
docker volume ls: list all volumes
docker volume crate postgres_vol-1: explicitly create a volume and give it a name.
flag -v and specify a name for the volume when you run the Container and map it to the directory, like this
docker run -v postgres_vol_2:/var/lib/postgresql/data --name volume-postgres -p 5433:5432 -d craig/postgres:version1
-p: binding a laptop port to a container port
-v: binding a host file directory to a virtual folder of the container; this case binding a named-volume to a specific virtual folder of the container.
docker volume --help: finding out other docker volume options
docker logs <containerName|containerId>: showing specific container logs.
show docker container log in a real time
docker logs --follow docker_container_id
'--follow' a full option name; or for a short, just '-f'. this option will tail the latest logs on the screen in a real time.
Docker Network
Docker Compose
Run Apache2 within Ubuntu container
now we run the Ubuntu container and mapping Apache2 80 to the Local system
dcoker run -it -p 80:80 -d ubuntu
-p: port
Apache2 normally working on port 80;
Apache2 will be running inside a container on the top of the docker, which resides on the local OS.
So we need to map the port of this container onto my local system.
now go inside the container
docker exec -it <container-id>
apt-get update
checking if Apache2 is running
service apache2 status
start the Apache2
service apache2 start
Run Postgres from Docker Container
Initialization scripts
If you would like to do additional initialization in an image derived from this one, add one or more *.sql, *.sql.gz, or *.sh scripts under /docker-entrypoint-initdb.d (creating the directory if necessary). After the entrypoint calls initdb to create the default postgres user and database, it will run any *.sql files, run any executable *.sh scripts, and source any non-executable *.sh scripts found in that directory to do further initialization before starting the service.
Difference between Docker and VM
To fully understand Docker, we also need to talk about the difference between Docker and a Virtual Machine (VM). The latter often runs in cloud environments like AWS and Azure. Whenever you create a VM you are sharing the hardware with others and other VMs. What these cloud environments are doing is 'virtualise' the hardware. Docker doesn't do that and does it differently. In a VM you can have multiple Operating Systems running on the same hardware, whilst with Docker, you virtualise the Operating System. Therefore, the big difference between VMs and Docker containers is that the former can have multiple (Guest) Operating Systems on the same hardware, through for example VMWare (which is called a Hypervisor). when you install Docker, you are going to use the Docker Engine to create isolated entities on the OS. These entities are called containers. Docker, therefore, allows you to automate the deployment of applications in these containers.
docker run --name=testMySql -e MYSQL_ROOT_PASSWORD=test -p 3306:3306 -d mysql:latest
sudo docker exec -it testMySql bash
bash-4.4# mysql -u root -p
mysql> show databases;
docker run --name=testMySql -e MYSQL_ROOT_PASSWORD=test -p 3306:3306 -d mysql:5.7.39
Monday, 12 September 2022
Creating SSH Pub Key
Goto user home, run
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/yichunzhao/.ssh/id_rsa):
Created directory '/Users/yichunzhao/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/yichunzhao/.ssh/id_rsa
Your public key has been saved in /Users/yichunzhao/.ssh/id_rsa.pub
The key fingerprint is:
cd user home directory
cd .ssh
cat id_rsa.pub (public key)
put this key in the github.
Can Jackson Deserialize Java Time ZonedDateTime
Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...
-
Could not extract response: no suitable HttpMessageConverter found for response type [class dk.enettet.evu.core.model.Address] and content ...
-
First time met this hibernate exception. I think this issue should due to one to one relationship. One driver has one car; one car has on...
-
A large object refers to the entity property that is modified by @Lob. It may be persisted in several records. However, in database manage...