Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a isolated "environment" in Ubuntu?

Tags:

Is there any way to create a isolated environment in Ubuntu 14.04? I have a unstable application installed and sometimes it doesn't work, I don't know why. So, I'm trying to make a isolate environment, in a way that the dependencies I install will be available only in this environment (something like python virtual environment).

The program needs these dependencies to be installed: libc6, libstdc++6, imagemagick, perl, libgl1-mesa-glx, and libglu1-mesa

I hope you have understood my question. Thank you!

like image 975
Julio Avatar asked Jun 28 '18 19:06

Julio


1 Answers

You can use Docker to create an isolated environment similar to a VM. You would have the have the Docker daemon running on your development machine (available on Mac, Windows, and Linux). You then create a Dockerfile that starts with the Ubuntu 14.04 base image. You can then use the Docker syntax to write commands to install your dependencies, and copy your code into the Docker container (instance of your isolated environment).

So let's say you have a basic java app and you are in the /app directory:

/app
|
├── /bin
|   └── app.jar
|
├── /src
|   └── app.java
|
└── Dockerfile

Your Dockerfile would look as follows to describe your isolated environment:

# Use the Ubuntu 14.04 base image
FROM ubuntu:14.04

# Install dependencies 
# (assuming they are available via apt-get)

# <install Java here>

RUN apt-get install -y \
libc6                  \
libstdc++6             \
imagemagick            \
perl                   \
libgl1-mesa-glx        \ 
libglu1-mesa       

# Copy code (or binaries) into the container
COPY app/bin/app.jar /app.jar

# Expose port 8080
EXPOSE 8080

# Run the application
CMD java -jar app.jar

You then need to build an image from the Dockerfile with the build command:

docker build -t app .

Then run it (let's say it exposes port 8080):

docker run -p 8080:8080 app

Now your app will be available at localhost:8080 on your development machine, but it will be running in an isolated Ubuntu container.

like image 96
Jabari Dash Avatar answered Oct 11 '22 14:10

Jabari Dash