Docker

Docker Basic Notes

This post is just a simple note. More detail in this video: https://www.youtube.com/watch?v=3c-iBn73dDE Difference Image and Container CONTAINER is a running environment for IMAGE virtual file system port blinded: talk to application running inside of container application image: postgres, redis, mongo, … redis in dockerhub are images docker pull postgres docker pull redis # lists installed images docker images docker run redis # `-d` means running in detached mode docker run -d redis # lists running container docker ps # lists running and stopped container docker ps -a # stops the container docker stop <CONTAINER ID> # start the container docker start <CONTAINER ID> # pulls image and starts container docker run redis:4.0 CONTAINER Ports vs HOST ports Multiple containers can run on your host machine Your laptop has only certain ports available Conflict when same port on host machine host docker Port 5000 Port 5000 Port 3000 Port 3000 Port 3001 Port 3000 docker run -p6000:6379 redis docker logs <CONTAINER ID> docker logs <CONTAINER NAMES> docker run -d -p6000:6379 --name redis-older redis:4.0 # it Interactive Terminal docker exec -it <CONTAINER ID> /bin/bash docker exec -it <CONTAINER NAMES> /bin/bash # if no bash installed docker exec -it <CONTAINER ID> /bin/sh docker exec -it <CONTAINER NAMES> /bin/sh # create a new container from a image docker run # start a exist container docker start docker pull mongo docker pull mongo-express docker network ls docker network create <NETWORK NAME> docker run -d \ -p 27017:27017 \ -e MONGO_INITDB_ROOT_USERNAME=admin \ -e MONGO_INITDB_ROOT_PASSWORD=password \ --network mongo-network \ --name mongodb \ mongo docker run -d \ -p 8081:8081 \ -e ME_CONFIG_MONGODB_ADMINUSERNAME=admin \ -e ME_CONFIG_MONGODB_ADMINPASSWORD=password \ -e ME_CONFIG_MONGODB_PORT=27017 \ -e ME_CONFIG_MONGODB_SERVER=mongodb \ --net mongo-network \ --name mongo-express \ mongo-express docker logs <CONTAINER ID> -f docker logs <CONTAINER ID> | tail docker logs <CONTAINER ID> | more Docker Compose docker run command ...

March 13, 2023 · Aimer Neige
Server Setup

How to Setup Your New Linux Server

Update System # Debian apt update # Fedora dnf update Install Most Used Tools # Debain apt install -y neofetch htop tree ncdu ranger zsh vim neovim git curl wget net-tools # Fedora dnf install -y neofetch htop tree ncdu ranger zsh vim neovim git curl wget util-linux-user Create Sudo User # Debian adduser aimer usermod -aG sudo aimer # Fedora useradd -G wheel aimer passwd aimer Test Root Privileges su - aimer sudo cat /etc/shadow Setup SSH Public Key Quickly Upload Your Local Key # run this on your local machine ssh-copy-id aimer@server Import The Key You Hosted # Import your own public key! wget https://aimer.aiursoft.cn/authorized_keys -O ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys Test if You Can Connect to Server ssh aimer@server Disable Root and Password Login sudo vim /etc/ssh/sshd_config Set PermitRootLogin as no To disable root login Set PasswordAuthentication as no To disable password login Delete this file /etc/ssh/sshd_config.d/50-cloud-init.conf ...

May 17, 2022 · Aimer Neige