我正在使用docker-compose运行3个容器 1-我的Web应用程序 2 Postgres 3-卡桑德拉
一旦我使用: docker-compose up
我的Web应用程序启动此异常: com.datastax.driver.core.exceptions.NoHostAvailableException:所有主机 尝试查询失败(尝试:cassandra / 172.17.0.3:9042
一旦所有容器都在运行,我就可以进入我的webapp并尝试在cassandras容器死亡(webapp容器)之前对其进行ping操作,并且成功返回了所有数据包,因此我猜它们之间确实存在连接。
最奇怪的是,一旦我得到了这个例外: .InvalidQueryException:键空间“ myKeyspace”不存在
这意味着已经建立了连接,但是那是在我添加持久性并创建所提到的架构之前,但是我并没有对compose.yml进行任何更改以得到这个新结果
这是我的docker-compose.yml:
public class Movie implements Parcelable {
@SerializedName("vote_count")
@Expose
private Integer voteCount;
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("video")
@Expose
private Boolean video;
@SerializedName("vote_average")
@Expose
private Double voteAverage;
@SerializedName("title")
@Expose
private String title;
@SerializedName("popularity")
@Expose
private Double popularity;
@SerializedName("poster_path")
@Expose
private String posterPath;
@SerializedName("original_language")
@Expose
private String originalLanguage;
@SerializedName("original_title")
@Expose
private String originalTitle;
@SerializedName("genre_ids")
@Expose
private List<Integer> genreIds = null;
@SerializedName("backdrop_path")
@Expose
private String backdropPath;
@SerializedName("adult")
@Expose
private Boolean adult;
@SerializedName("overview")
@Expose
private String overview;
@SerializedName("release_date")
@Expose
private String releaseDate;
protected Movie(Parcel in) {
voteCount = in.readByte() == 0x00 ? null : in.readInt();
id = in.readByte() == 0x00 ? null : in.readInt();
byte videoVal = in.readByte();
video = videoVal == 0x02 ? null : videoVal != 0x00;
voteAverage = in.readByte() == 0x00 ? null : in.readDouble();
title = in.readString();
popularity = in.readByte() == 0x00 ? null : in.readDouble();
posterPath = in.readString();
originalLanguage = in.readString();
originalTitle = in.readString();
if (in.readByte() == 0x01) {
genreIds = new ArrayList<Integer>();
in.readList(genreIds, Integer.class.getClassLoader());
} else {
genreIds = null;
}
backdropPath = in.readString();
byte adultVal = in.readByte();
adult = adultVal == 0x02 ? null : adultVal != 0x00;
overview = in.readString();
releaseDate = in.readString();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
if (voteCount == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeInt(voteCount);
}
if (id == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeInt(id);
}
if (video == null) {
dest.writeByte((byte) (0x02));
} else {
dest.writeByte((byte) (video ? 0x01 : 0x00));
}
if (voteAverage == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeDouble(voteAverage);
}
dest.writeString(title);
if (popularity == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeDouble(popularity);
}
dest.writeString(posterPath);
dest.writeString(originalLanguage);
dest.writeString(originalTitle);
if (genreIds == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeList(genreIds);
}
dest.writeString(backdropPath);
if (adult == null) {
dest.writeByte((byte) (0x02));
} else {
dest.writeByte((byte) (adult ? 0x01 : 0x00));
}
dest.writeString(overview);
dest.writeString(releaseDate);
}
@SuppressWarnings("unused")
public static final Parcelable.Creator<Movie> CREATOR = new Parcelable.Creator<Movie>() {
@Override
public Movie createFromParcel(Parcel in) {
return new Movie(in);
}
@Override
public Movie[] newArray(int size) {
return new Movie[size];
}
};
}
卷: postgresdata:
谢谢大家
答案 0 :(得分:1)
我假设您的Web应用程序要求cassandra服务在启动时才能运行。您应该将depends_on
条目添加到您的Web应用程序服务中,以便docker仅在启动cassandra时启动它
并且links
条目不是必需的,因为docker会自动使用服务名称作为为此docker-compose项目创建的网络中的主机名。 network_type: bridge
也是一样-这是默认的网络类型,因此您可以在这种情况下忽略它。