Create a network named "test"
docker network create test
Create two containers using the network
docker run --name c1 --network "test" --rm --entrypoint tail mongo -f
docker run --name c2 --network "test" --rm --entrypoint tail mongo -f
Enter one container to ping the other and it will work
docker exec -it c1 bash
apt-get install iputils-ping # install command ping
root@79568c5ce391:/usr/src/app# ping c2
PING c2 (172.18.0.3) 56(84) bytes of data.
64 bytes from c2.test (172.18.0.3): icmp_seq=1 ttl=64 time=0.137 ms
64 bytes from c2.test (172.18.0.3): icmp_seq=2 ttl=64 time=0.221 ms
64 bytes from c2.test (172.18.0.3): icmp_seq=3 ttl=64 time=0.232 ms
...
Using default network or "bridge" network does not work:
docker run --name c1 --rm --entrypoint tail web_scraper:v1 -f
docker run --name c2 --rm --entrypoint tail web_scraper:v1 -f
docker run --name c1 --network "bridge" --rm --entrypoint tail web_scraper:v1
$ docker run -p 127.0.0.1:80:8080/tcp ubuntu bash
This binds port 8080 of the container to TCP port 80 on 127.0.0.1 of the host machine. You can also specify udp and sctp ports.
$ docker run --expose 80 ubuntu bash
This exposes port 80 of the container without publishing the port to the host system’s interfaces.
Set up the same locale
in both of the local laptop and remoter server:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
Use the lsblk
command to list the block devices attached to the instance
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 30G 0 disk
`-xvda1 202:1 0 8G 0 part /
loop0 7:0 0 91M 1 loop /snap/core/6405
loop1 7:1 0 87.9M 1 loop /snap/core/5742
loop2 7:2 0 17.9M 1 loop /snap/amazon-ssm-agent/1068
loop3 7:3 0 16.5M 1 loop /snap/amazon-ssm-agent/784
loop4 7:4 0 18M 1 loop /snap/amazon-ssm-agent/930
Use the df -h
command to report the existing disk space usage on the file system
$ sudo df -h /dev/xvd*
Filesystem Size Used Avail Use% Mounted on
udev 488M 0 488M 0% /dev
/dev/xvda1 7.7G 7.4G 370M 96% /
Expand the modified partition using growpart
$ sudo growpart /dev/xvda 1
CHANGED: partition=1 start=2048 old: size=16775135 end=16777183 new: size=62912479,end=62914
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot python-certbot-nginx
Running this command will get a certificate for you and have Certbot edit your Nginx configuration automatically to serve it.
sudo certbot --nginx
# for a specific name
sudo certbot --nginx -d example.com
The Certbot packages on your system come with a cron job that will renew your certificates automatically before they expire.
You can test automatic renewal for your certificates by running this command:
sudo certbot renew --dry-run
docker images
docker build -t image_name .
docker rmi $(docker images | grep "^<none>" | awk "{print $3}") # remove all untagged images
docker save image_name > image_name.tar # save image as a tar file
docker load < busybox.tar.gz # load image
docker run -p 27017:27017 -v mongodbdata:/data/db mongo
docker ps -a
docker exec -it ubuntu_bash bash
docker rm container_name
docker rm $(docker ps -a -q) # remove all stopped containers
docker volume create mongodbdata
docker volume ls
docker volume inspect mongodbdata
docker network ls
docker network create network_name
docker network inspect network_name
docker network rm network_name
docker login azure --tenant-id 8432da0f-f8af-4b02-b318-4c777cfab498
docker context create aci hpjacicontext
docker context use hpjacicontext
docker compose up
Sample Code: https://github.com/guangningyu/react-skeleton
wget http://downloads.lightbend.com/scala/2.11.8/scala-2.11.8.rpm
mkdir -p src/main/java/hello
mkdir -p src/test/java/hello
src/main/java/hello/HelloWorld.java
package hello;
import org.joda.time.LocalTime;
public class HelloWorld {
public static void main(String[] args) {
LocalTime currentTime = new LocalTime();
System.out.println("The current local time is: " + currentTime);
Greeter greeter = new Greeter();
System.out.println(greeter.sayHello());
}
}
src/main/java/hello/Greeter.java
package hello;
public class Greeter {
public String sayHello() {
return "Hello world!";
}
}
src/test/java/hello/GreeterTest.java
package hello;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.*;
import org.junit.Test;
public class GreeterTest {
private Greeter greeter = new Greeter();
@Test
public void greeterSaysHello() {
assertThat(greeter.sayHel
> var _ = require('lodash');
> foo
{ a: { num: 1 }, b: { num: 2 }, c: { num: 3 } }
> _.forEach(foo, (vlu, key) => {console.log(vlu, key);})
{ num: 1 } 'a'
{ num: 2 } 'b'
{ num: 3 } 'c'
{ a: { num: 1 }, b: { num: 2 }, c: { num: 3 } }
> foo
{ a: { num: 1 }, b: { num: 2 }, c: { num: 3 } }
> _.pickBy(foo, (i) => i.num>=2)
{ b: { num: 2 }, c: { num: 3 } }
DEFAULT=5
RESULT=${VAR:-$DEFAULT}
function rollback() {
if [[ $? -ne 0 ]]; then
echo "rollback"
fi
}
set -ueo pipefail
trap rollback EXIT
#!/bin/bash
FILE="/etc/passwd"
if [[ -f $FILE ]];then
echo "$FILE exists"
else
echo "$FILE doesn't exist"
fi
#!/bin/bash
DIR="/var/log"
if [[ -d $DIR ]]; then
echo "$DIR exists"
else
echo "$DIR doesn't exist"
fi
function assert_var_exists() {
local condition="[[ ! -n \"\${$1+set}\" ]]"
if eval $condition; then
echo "The variable ${1} does not exist. Exit."
exit 1
fi
}
function export_var() {
assert_var_exists $1
local var_value=$(($1))
eval "export $1=\$var_value"
echo "$1=$var_value"
}
uname -m
lsb_release
git config --global user.name "Guangning Yu"
git config --global user.email "hi@guangningyu.com"
git remote -v
git remote set-url origin git@github.com:guangningyu flasky.git
git pull origin master
git push origin master
git commit —no-edit
git reset HEAD~
git reset filename.txt
GIT_COMMITTER_NAME='Jane Doe' GIT_COMMITTER_EMAIL='jane@doe.com' git commit —author="John Doe <john@doe.com>" -m "This is authored by John Doe and committed by Jane Doe."
git checkout HEAD path/to/file
git branch -a
git checkout test_branch
git checkout -b [name_of_your_new_branch]
git push -u origi
my_array.slice(-1)[0]
my_array.pop()