Thursday 2 May 2019

Docker cheatsheet

List all running and stopped containers

docker ps -a

Remove a container

docker rm my_container

Stop a container

docker stop my_container

Start a container

docker start my_container

Run a container

docker run --name sonarqube\
    -p 9000:9000 \
    -e sonar.jdbc.username=sonarqube \
    -e sonar.jdbc.password=password \
    -e sonar.jdbc.url="jdbc:mysql://host.docker.internal:3306/sonarqube?useUnicode=true&characterEncoding=utf8" \
    sonarqube
Use -d to run it in background

MySQL Cheatsheet

Open MySQL command line

mysql -u root -p

Show all databases

show databases;

Create new database


CREATE DATABASE dl_edeposit;

Show all users


SELECT host, user, password FROM mysql.user;

Create new user


CREATE USER 'dl_edeposit'@'localhost' IDENTIFIED BY 'password';

Grant privilege to a user on a table


GRANT ALL PRIVILEGES ON dl_edeposit.* TO 'dl_edeposit'@'localhost';

Create SSH public/private key

The aim is to be able to connect to (ssh) a remove server without a password.

you@local$ssh-keygen -t rsa -b 4096 -C [your username (e.g. msun]

When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
Enter your password twice.


Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

Copy the public key to the remote server


you@local$ cat ~/.ssh/id_rsa.pub | ssh msun@<remove server> 'cat - >> ~/.ssh/authorized_keys'
you@remote's password:

Store your password to the keychain. This ensures you don't need to type password in other terminal session


ssh-add -K ~/.ssh/id_rsa

Reference:

http://mah.everybody.org/docs/ssh#upload-public-key
https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/