This Docker image provides a lightweight Ubuntu-based environment with SSH access enabled. It allows you to securely connect to the containerized environment via SSH. The image is designed to be customizable by allowing you to set a root password and create a non-root user with sudo privileges.
docker run -d -p <host_port>:22 --name <container_name> -e ROOT_PASSWORD=<password> -e USERNAME=<username> vikesh001/ubuntu-ssh
Replace <host_port> with the desired host port for SSH access, <container_name> with your chosen container name, with your desired root password, and with the non-root username you want to create.
ssh <username>@localhost -p <host_port>
Replace with the non-root username you specified and <host_port> with the host port you mapped when running the container.
Run a Docker container using the newly built image:
docker run -d -p 1234:22 --name ssh-container -e ROOT_PASSWORD=myrootpass -e USERNAME=myuser vikesh001/ubuntu-ssh
-d: Run the container in the background (detached mode). -p 1234:22: Map port 1234 on the host to port 22 in the container for SSH access. --name ssh-container: Assign the name "ssh-container" to the running container. -e ROOT_PASSWORD=myrootpass: Set the root password to "myrootpass". -e USERNAME=myuser: Create a non-root user named "myuser".
Step 3: Connect via SSH
Now you can connect to the running container using SSH:
ssh myuser@localhost -p 1234
Provide the password when prompted (in this example, use "myrootpass").
Note: Since port 1234 was mapped on the host, you can also connect to the container using a different machine on your network by replacing "localhost" with the IP address or hostname of the host machine.
To stop and remove the container, you can use the following commands:
docker stop ssh-container
docker rm ssh-container
This example demonstrates how to create a Docker image with SSH access, run a container from the image, and connect to the container using SSH. You can customize the root password, username, and other configurations as needed for your specific use case.
Note: For enhanced security, it's recommended to avoid using well-known port numbers like 2222 for SSH. Instead, you can use the -P option with docker run to let Docker choose a random host port for mapping to the container's SSH port (22).
This Docker image is designed to provide a flexible and secure SSH-accessible environment for various use cases. Customize the image by setting the root password, username, and any other configurations you require.
Content type
Image
Digest
sha256:2f1c2acdd…
Size
68.7 MB
Last updated
about 3 years ago
docker pull vikesh001/ubuntu-ssh