Creating an Ubuntu Image

1. Pull the Ubuntu image

docker pull ubuntu
Copy the code

2. Check whether the pull is successful

docker images
Copy the code

3, run the container

Docker run --name Name of the new container - ti-v /AAA:/ bbb-d-p 3316:22 ubuntuCopy the code

  • The AAA folder in the root directory of the host is mapped to the container and can be shared between the two
  • – name Specifies the name of the generated container
  • -i: Runs the container in interactive mode to ensure that STDIN is enabled in the container. Usually used together with -t;
  • -t: reallocates a pseudo TTY terminal to the container. It is usually used together with -i.
  • -d: runs the container in the background and returns the container ID.
  • -p: You can specify the IP address and port to be mapped, but only one container can be bound to a specified port. Supported formats have hostPort: containerPort, IP: hostPort: containerPort, IP: : containerPort.
  • Ubuntu is the image name, and the image ID is fine.

4. Check whether the container is running successfully

  • Docker ps -a View all containers, including started and suspended containers

Matters needing attention

  • This is an extremely streamlined system, without even the most basic wGET command; Apt-get install wget command apt-get install wget

  • To exit the system correctly, press CTRL + P first. CTRL + Q. You must not use exit or CTRL + D to exit, and the entire system will exit. For MAC computers, use control instead of CTRL

  • Run the Docker ps -a command to find the CONTAINER ID (for example, 0a3309a3b29e). 2. Open the system and run the docker attach 0a3309a3b29e command

Installing the SSH Service

1. Go to the container terminal

Docker exec -t -i new container name /bin/bashCopy the code

  • Or see the note above: After exiting, how do I enter the container terminal

2. Perform the update operation

  • Apt-get update (apt-get update

3. Install sSH-client and Ssh-server

apt-get install openssh-client
apt-get install openssh-server
Copy the code

  • Wait and type Y to complete the installation

4, after the installation is complete, you can start the service

/etc/init.d/ssh start
Copy the code

5. Check whether the startup is successful

ps -e|grep ssh
Copy the code

6. Edit the sshd_config file

  • Install the vim editor apt-get install vim
  • Edit the sshd_config file, add PermitRootLogin yes, run Esc + :, and enter WQ to save the changes and exit the file editing window

7. Restart the SSH service

  • service ssh restart

8. Set the SSH password

  • Passwd root, this process needs to be entered twice

9. View the IP address of the container

  • Install the installation package apt-get install net-tools first
  • View the IP address ifconfig

10. Save the modified image

  • Docker commit [REPOSITORY ID] [REPOSITORY:TAG]

Use the Shell tool to connect

  • You can connect with localhost:3316 or with local IP:3316

Supplements common commands

Check out the Ubuntu version:

  • cat /etc/issue

SSH Commands

  • Service SSH start Starts the SSH service
  • Service SSH stop Stops the SSH service
  • Service SSH restart Indicates the restart

Refer to the link

  • Docker install Ubuntu and SSH connection
  • Ubuntu runs in the Docker container
  • Docker port mapping
  • How Docker sets port mapping to a running container
  • Four ways to enter Docker