Instance creation is omitted
-#Change key pair permissions
%chmod 400 key pair.pem
-#Ssh connect to ubuntu instance
% ssh -i key pair.pem ubuntu@EC2 public DNS
yes
The purpose of changing the authority of the key pair is to use "400" and ** read-only ** key pair because ssh connection cannot be made if it is rewritten by mistake. Note that EC2 public DNS changes by ** stopping ** and ** starting ** the instance!
-#I don't have access privileges, so I use sudo to update.
$ sudo apt-get update
-#install docker
$ sudo apt-get install docker.io
-#Press Y
-#Check docker version
$ docker -—version
At this rate, ubuntu doesn't have permission for docker, so you have to prefix the command with ** "sudo" ** every time. So create a group called "docker" and put "ubuntu" in it. Then, since "ubuntu" belongs to the "docker" group, docker can be used and commands can be used without "sudo".
-#Put "ubuntu" in a group called "docker"
$ sudo glassed -a ubuntu docker
Adding user ubuntu to group docker
-#It will not be reflected unless it comes out once
$ exit
-#ssh connect
% ssh -i key pair.pem ubuntu@EC2 public DNS
-#Check docker command
$ docker images
You can confirm that the docker command can be used.
-#Creating a Docker image to send to EC2
% mkdir temp_folder
% cd temp_folder
% vim Dockerfile
Dockerfile
FROM alpine
RUN touch test
% docker build .
Create a lightweight alpine and create a file called "test" in it.
-#docker save image name>New name.tar
% docker save b3fc1a6f13e6 > myimage.tar
-#Check tar file
% ls
The command to use when transferring files.
-#Enter sftp(The state where the host and the instance are connected)
% sftp -I key pair.pem ubuntu@EC2 public DNS
-#put File path to send File path to destination
sftp> put temp_folder /home/ubuntu
-#Open another terminal, change to the directory where the key pair is, and ssh it.
% ssh -i mydocker.pem [email protected]
-#Check if there is a file
$ ls
You can see that the file has been transferred from the host to EC2.
-#Creating a file on EC2
$ touch test
-#Open another terminal, go to the host side, enter sftp
% sftp -I key pair.pem ubuntu@EC2 public DNS
-#Make sure you have the test file
sftp> ls
-#Get the test file
sftp> get test
-#Exit sftp
sftp> exit
Make sure you have a "test" file on your desktop
#ssh connect
% ssh -i key pair.pem ubuntu@EC2 public DNS
# docker load <Return to image with tar faril
$ docker load < my image.tar
#Confirm image
$ docker images
# docker run(alpine doesn't have bash so sh)
$ docker run -it image ID sh
#Make sure you have the test file with the ls command
ls
-#Enter sftp
% sftp -I key pair.pem ubuntu@EC2 public DNS
-#Send Dockerfile with put, if you do not specify the destination, it will be put to ubuntu's home directory
%Absolute path of put Dockerfile
-#ssh connect
% ssh -i mydocker.pem [email protected]
-#Check the Dockerfile
$ ls
-#Creating a build context
$ mkdir dsenv_build
-#Move Dockerfile
$ mv Dockerfile dsenv_build/
$ cd dsenv_build
-#Launch the container
$ docker build .
However, ** storage (8GB) ** is not enough to build.
# -h at M,Gbyte display
$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 476M 0 476M 0% /dev
tmpfs 98M 768K 98M 1% /run
/dev/xvda1 7.7G 5.1G 2.7G 66% /
tmpfs 490M 0 490M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 490M 0 490M 0% /sys/fs/cgroup
/dev/loop0 97M 97M 0 100% /snap/core/9804
/dev/loop1 29M 29M 0 100% /snap/amazon-ssm-agent/2012
tmpfs 98M 0 98M 0% /run/user/1000
With 8GB, "/" is already using 5.1G, and the rest is only 2.7GB, so when building, there is not enough storage to build. By the way, in case of Linux, the storage location of Docker object is "/ var / lib / docker /".
-#ssh connection
% ssh -i mydocker.pem [email protected]
-#Go to the location of the Dockerfile
$ cd dsenv_build
-#Build again
$ docker build .
-#Now that the storage is 20GB, you can build without any problems.
$ docker run -v~:/work -p 8888:8888 Image ID
You can confirm that you can connect with EC2 public DNS: 8888.
-# $sudo adduser —uid any ID username(Note that users cannot be created without sudo privileges)
-#I'm asked a lot, but this time I omitted everything with enter
$ sudo adduser --uid 1111 aaa
-# /home/Moved because a directory called aaa has been created
$ cd /home/aaa
-#Create another user
$ sudo adduser --uid 2222 bbb
-#Return to home directory
$ cd /home
-#Check file permissions.
$ ls -la
-#You can check the permissions of the aaa and bbb files, and you can see that aaa cannot write to the bbb directory.
-#Enter as a aaa user
docker run -u 1111 -v /home/aaa:/home/aaa -v /home/bbb:/home/bbb -it ubuntu bash
-#Confirm id
1111
It can be confirmed that it is entered as a user of aaa.
-#Move to bbb directory
$ cd /home/bbb
-#Create file
$ touch test
However, it can be confirmed that it cannot be created because it does not have write permission.
Recommended Posts