English
luckfu's notes.

Never forget your dreams!


  • Home

  • Archive

  • About

  • Page404

  • Search

Use the docker container as a virtual machine

Published at: 2021/07/15   |   Categories: cloud vps   Docker   | Words: 577 words | Reading: 2 minutes | Visited:

The last article mentioned that Oracle Cloud’s free and popular 4c24g VM.Standard.A1.Flex model is difficult to apply, but in actual use, there are still many traps in the Oracle Cloud free package. The following are some common situations:

Free hosting is over quota, free storage is over quota, oc priority to stop the resource is this A1.Flex vps 。

Flex.A1 The optional operating system is only oracle linux v7 or v8 , if you like ubuntu…😭

When the operating system is broken, unlike general cloud service consoles that can restore the image, you can only reapply

Using a container as a virtual machine is not in line with the original intention of container application deployment, but in view of the above problems, docker is used to create a container instead of a virtual machine in this article. Everything is operated in the virtual machine. When the system disaster is unrecoverable, just delete container and Create the container again.

Deployment steps

ssh Log in to the host

1、Install docker

yum install docker

2、Dockerfile

Writing Dockerfile

FROM ubuntu:20.04
LABEL MAINTAINER="luckfu.com"
USER root

# change root password to `ubuntu`
RUN echo 'root:ubuntu' | chpasswd 
ENV DEBIAN_FRONTEND noninteractive

# install ssh server
RUN apt-get update && apt-get install -y \
  openssh-server sudo \
  && rm -rf /var/lib/apt/lists/* \
  && mkdir -p /run/sshd \
  && ssh-keygen -A \
  && sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config \
  && apt-get purge -y --auto-remove 

EXPOSE 22

# run ssh server
CMD ["/usr/sbin/sshd", "-D", "-o", "ListenAddress=0.0.0.0"]

3、Generate image

docker build -f ./Dockerfile -t ubuntu-ssh

docker images view image list

docker images
REPOSITORY     TAG       IMAGE ID       CREATED       SIZE
ubuntuos-ssh   latest    b6010c26ebb7   1 days ago   189MB
ubuntu         20.04     d5ca7a445605   8 weeks ago   65.6MB

4、Launching containers

执行命令

docker run -d -p 9022:22  -p 8000-9000:8000-9000 \
-v /data/:/data \
--name ubuntuos-ssh ubuntuos-ssh 

parameters and meaning:

ParametersDescription
-dDaemon mode
-pPort Mapping [host port:Port in container]
-vvolume mapping [host vol:container vol]
–namecontainer name ubuntu-ssh

In the above command, we deployed a container named ubuntuos-ssh, and set the host’s /data (you can apply for 100G “always free” storage in the oracle cloud and mount it to the host /data) is mounted under the /data of the container, and 9022 of the host is mapped to port 22 of the ssh service of the container, and ports 8000-9000 are opened for spare

Check if the container is running

CONTAINER ID   IMAGE          COMMAND                  CREATED        STATUS        PORTS                                                                                                  NAMES
0c9cf191daf2   ubuntuos-ssh   "/usr/sbin/sshd -D -…"   12 days ago    Up 12 days    0.0.0.0:8000-9000->8000-9000/tcp, :::8000-9000->8000-9000/tcp, 0.0.0.0:9022->22/tcp, :::9022->22/tcp   ubuntuos-ssh

Log in to the container

use ssh instead of exec -it to enter

password: ubuntu

ssh root@localhost -p 9022
root@localhost's password:
(base) root@xxxxxxx:~# 

If login success, the container is running normally

5、Login from internet

Login to Oracle Cloud

  • Check VNC config ,port 22 8000-9000 used by the container is open
  • checks the firewall such as iptables firwwall,port is open
ssh root@IP -p 9022

Let’s play

#Oracle Cloud# #Free VPS# #docker# #VM.Standard.A1.Flex#

Declaration:Use the docker container as a virtual machine

Link:http://www.luckfu.com/en/post/ampere_a1_docker/

Author:luckfu

Declaration: This blog post article is under the CC BY-NC-SA 3.0 license,Please indicate the source!

If it can help you, you can give tips for blogger that how much you want. ^_^
WeChat Pay

Wechat Pay

Alipay

Ali Pay

paypal Pay

PayPal

Where is the Bluetooth PAN in macOS Monterey? 😡
Use python scripts to preemptively create Oracle VM.Standard.A1.Flex
  • Table of Content
  • Site Information
luckfu

luckfu

In a flash, all of the past away from you, the rest of the only memories.

5 Blogs
11 Categories
14 Tags
GitHub
TagCloud
  • Oracle cloud
  • Free vps
  • Vm.standard.a1.flex
  • Automation script
  • Bluetooth pan
  • Docker
  • Financials
  • Macos
  • Metabase
  • Monterey
  • 1、Install docker
  • 2、Dockerfile
  • 3、Generate image
  • 4、Launching containers
  • 5、Login from internet
© 2010 - 2025 luckfu's notes.
Powered by - Hugo v0.127.0 / Theme by - NexT
0%